一些项目使用Object.create()
或Object.defineProperties()
功能。我想知道是推荐的吗?有什么区别
x = Object.create(null);
对比
x = {}
和
x = {}
x.__proto__.hello = function() {
console.log("hello");
}
对比
x = Object.create(null);
Object.defineProperty(x, "hello", {
value: function() {
console.log("hello");
}
});
defineProperty/create
对我来说似乎非常冗长和冗长。我何时/为什么使用它们?也许好的可能是强制执行 getter/setter/overriding 属性?