es6 -> 有类的概念 es5 -> 用函数充当类.
声明类:
class Beauty {
私有属性。constructor -> 类似于es5的构造函数,专门用来创建私有属性
constructor(name){
this.name = name;
}
公有属性
sleep(){
console.log(this.name);
}
}
om.__proto__ == Beauty.prototype -> es6也是true
typeof Beauty -> 'function'.es6的类本质上还是函数,但是就是写法不一样了.
om -> Beauty.prototype -> Object.prototype
Beauty.prototype.hasOwnProperty('sleep'); -> true 公有方法还是添加到了类的原型上
var om = new Beauty('小小');
es6实例化对象
最新推荐文章于 2024-04-17 17:01:03 发布