构造函数
function Person(){}
Person.prototype = {}
Person.prototype.constructor == Person // false
class
类
class Person{}
Person.prototype = {}
Person.prototype.constructor == Person // true
为什么构造函数和 class
重写原型之后的表现不一致,是因为 class
的 prototype
属性不能重写吗?
没有找到相关的资料,希望看到的大佬指点一下
Object.defineProperty 属性描述符
普通情况:
输出一下
Class
属性描述符:writable = false
不可重写模拟一下:
补充两种声明区别: