看板 Ajax 關於我們 聯絡資訊
想請教關於 Object.create 所 return 的物件屬性 我目前寫了一段code,如下: ------------------------------------------- let a = Object.create({}, { foo: { value: 1, enumerable: true, writable: true, configurable: true }, bar: { value: 2, enumerable: false, writable: false, configurable: false } }) let b = Object.create(a) console.log(Object.getPrototypeOf(b)) ------------------------------------------- 我把這段code跑在四個不同的地方,分別是: 1. Firefox 51.0.1 的 debug console 2. Chrome 56.0.2924.87 debug console 3. NodeJS 7.5.0 和從github上checkout最新版 4. v8 checkout from github 在1, 2中,最後的console.log會顯示 ['foo', 'bar'] 在3, 4中,則會顯示['foo'] 想請教是我哪邊有理解錯誤,導致結果不如我預期? 另外想再請教,Chrome內部應該也是用v8做js的engine 為什麼結果和單純使用v8結果不同? 還請先進賜教,感謝 -- ˍˍ 很多人在即將失去的時候,不知他即將失去,最後他就真正失去 ▕天險▏ 其實,一個不曾失去的人最可憐。因為,他永遠學不會什麼叫珍惜。▕刀藏▏  ̄ ̄ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.134.71.154 ※ 文章網址: https://www.ptt.cc/bbs/Ajax/M.1487899993.A.4BF.html
mrbigmouth: 我測試了一下 執行結果的b應該都是一樣的 只是後兩 02/24 10:09
mrbigmouth: 個環境下的console.log不會把enumerable:false的東西 02/24 10:10
mrbigmouth: 拿出來顯示 之所以會如此的原因不明 02/24 10:10
godman362: 那想請教,那getPrototypeOf的結果算相同嗎? 02/24 10:26
godman362: 照m大的說法,是console module過濾掉 02/24 10:26
godman362: 可是我在standalone v8底下也是這樣,沒console module 02/24 10:26
godman362: 我在v8內是把console換成JSON.stringify 02/24 10:27
godman362: 結果和我內容描述的一樣 02/24 10:27
godman362: 所以這樣是JSON.stringify也過濾了enumerable嗎? 02/24 10:28
godman362: 還請不吝賜教 02/24 10:28
mrbigmouth: JSON.stringify本來就會濾掉enumerable 你在前兩個環 02/24 10:39
mrbigmouth: 境執行的結果應該一樣喔 02/24 10:39
mrbigmouth: getPrototypeOf結果是相同的 都是a 我上面講不清楚 02/24 10:40
godman362: 喔,了解了,謝謝指點<(__ __)> 02/24 10:40