SOURCE

class Point {
    //如果没有一个显示定义,一个空的constructor()方法会被默认添加.
    //constructor()方法默认返回this
}

console.log(Point.prototype.constructor === Point)

class Foo {
    constructor() {
        return "abc";
    }
}

let foo = new Foo();
console.log(foo)


class CustomHTMLElement {
    constructor(element) {
        this.element = element;
    }

    get html() {
        return this.element;
    }

    set html(value) {
        this.element = value;
    }
}
//prototype是一个实例. 一个类只有一个的实例对象
var descriptor = Object.getOwnPropertyDescriptor(CustomHTMLElement.prototype, "html");
//说明这个属性方法 是放在类的原型对象上面的.而不是直接存在实例上的. 其实这么理解 所有方法全部都在原型上.属性就是特殊的方法
console.log("get" in descriptor);
console.log("set" in descriptor);



//------------立即执行Class----------------//
let person=new class{
    constructor(name){
        this.name=name;
    }

    sayName(){
        console.log(this.name);
    }
}('zhangsan')

person.sayName();

//----------------//
class Logger {
  printName(name = 'there') {
      console.log(this);
    this.print(`Hello ${name}`);
  }

  print(text) {
    console.log(text);
  }
}

const logger = new Logger();
logger.printName()
const { printName } = logger;
printName();//强行提出来printName方法. 里面的this是找不到print函数的
console 命令行工具 X clear

                    
>
console