【发布时间】:2017-06-12 01:38:03
【问题描述】:
通过 es6 类语法创建的公共方法是不可枚举的。 es5 和 es6 写的 getname 方法有什么区别?
function Cat(){
this.name="cat"
}
Cat.prototype.getname = function() {return this.name}
var cat = new Cat()
class Dog {
constructor(){
this.name="dog"
}
getname() {
return this.name
}
}
var dog = new Dog()
cat.__proto__.propertyIsEnumerable("getname") //true
dog.__proto__.propertyIsEnumerable("getname") //false
【问题讨论】:
标签: javascript ecmascript-6 ecmascript-5