作爲在javascript初學者,我試圖從這裏的Object.create方法以JavaScript
https://developer-new.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object/create
在該示例代碼理解的Object.create()方法,線18,一種存取屬性與創建可寫設置爲true。我還讀到,該寫入僅適用於數據描述符。
試圖運行,
var o = Object.create(Object.prototype, {
// foo is a regular "value property"
foo: {
writable:true, configurable:true, value: "hello"
},
// bar is a getter-and-setter (accessor) property
bar: {
writable: true,
configurable: false,
get: function() { return 10 },
set: function(value) { console.log("Setting `o.bar` to", value) }
}
});
console.log(o);
我得到invalid property error
。
是mozilla引用不正確? – John 2012-07-27 05:42:57
Mozilla的參考確實是不正確的。這是一個wiki,所以我只是登錄並修復它。 (他們很快就推出了一個新wiki,所以你可能還沒有看到這個修復,這取決於你是否參加了測試版,我認爲。) – apsillers 2012-07-27 05:52:30