class Point {
constructor(name) {
this.name = name;
}
walk = () => {
console.log("Point walk---");
}
say() {
console.log("Point say---");
}
}
// 类的数据类型就是函数
console.log(typeof Point); // function
// 类本身就指向构造函数
console.log(Point === Point.prototype.constructor); // true
console.log(Point.__proto__.name);
Point.prototype.say();
// 报错
// Point.prototype.walk();
const p1 = new Point("ljs");
const p2 = new Point("ljs");
p1.walk();
console.log(p1.constructor === Point.prototype.constructor); // true
console.log(p1.__proto__ === Point.prototype); // true
console.log(p1.hasOwnProperty('say')); // false
console.log(p1.hasOwnProperty('name')); // true
// 类的内部所有定义的方法,都是不可枚举的
console.log(Object.keys(Point.prototype));
// []
console.log(Object.getOwnPropertyNames(Point.prototype));
console.log(Reflect.ownKeys(Point.prototype));
// ["constructor", "say"]
console.log(Object.getOwnPropertyDescriptors(Point.prototype));
// {"constructor":{"writable":true,"enumerable":false,"configurable":true},"say":{"writable":true,"enumerable":false,"configurable":true}}
// 类的所有实例共享一个原型对象
console.log(p1.__proto__ === p2.__proto__);
console