iT邦幫忙

2021 iThome 鐵人賽

DAY 12
0
Modern Web

YDKJS 一邊讀 You Don't Know JS Yet 一邊卡關一邊弄懂的日子 ԅ(≖‿≖ԅ)系列 第 12

Day12 - this&Object Prototypes Ch3 Objects - Contents - Existence - Enumeration

將 enumerable 設為 false 的 property,在迴圈時無法被 in operator 發現

var myObject = { }; 
Object.defineProperty(
	myObject,"food",
  { enumerable: true, value: '燃麵' }
);

Object.defineProperty(
	myObject,"dessert",
  { enumerable: false, value: '大蛋糕' }
);

console.log("dessert" in myObject); // true
console.log(myObject.hasOwnProperty( "dessert" )); // true

for (item in myObject) {
	console.log( item );
} // 卻只有 'food'

今天記到這邊,大家晚安,如果以上內容有理解錯誤的地方都希望能再協助糾正,感恩的心 ԅ(≖‿≖ԅ)


上一篇
Day11 - this&Object Prototypes Ch3 Objects - Contents - Existence
下一篇
Day13 - this&Object Prototypes Ch3 Objects - Contents - Existence - Enumeration 作者建議
系列文
YDKJS 一邊讀 You Don't Know JS Yet 一邊卡關一邊弄懂的日子 ԅ(≖‿≖ԅ)30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言