[]
圍起的字串運算式,即可從物件中擷取值。.
註記。undefined
。var stooge = {
"first-name": 'Joe',
'last-name': 'Howard'
};
stooge['middle-name']; //undefined
||
運算子能用於填入預設值。stooge['first-name'] = 'Jerome';
stooge['middle-name'] = 'Lester';
var a = {}, b = {}, c = {};
// 各自參考不同物件
a = b = c = {};
// 參考同一空物件
Object.prototype
。typeof
可以幫助判斷特性型別。hasOwnProperty
可檢查物件所擁有的特性(部會檢索原型鏈)for-in
迴圈處理物件的特性,也可搭配 hasOwnProperty
過濾不需要的值。var name;
for (name in another_stooge) {
if (typeof another_stooge[name] !== 'function'){
document.writeln(name + ': ' + another_stooge[name]);
}
}
delete
可從物件移除特性,不會影響物件聯繫的其他物件。another_stooge.nickname; //'Moe'
delete another_stooge.nickname;
another_stooge.nickname; //'Curly'
var MYAPP = {};
MYAPP.stooge = {
"first-name": "Joe",
"last-name": "James",
};
MYAPP.flight = {
airline: "Oceanic"..
..
}
資料來源:《JavaScript 優良部份》 Douglas Crockford 著 歐萊禮
筆記純屬推廣及分享,如有侵權,請告知。
Please advise to remove immediately if any infringement caused.