标签:
// 3.1 code 1 var empty_object = {}; var stooge = { "first-name": "Jerome", "last-name": "Howard" };
// 3.1 code 2 var filght = { airline: "Oceanic", number: 815, departure: { IATA: "SYD", time: "2004-09-22 14:55", city: "Sydney" }, arrival: { IATA: "LAX", time: "2004-09-23 10:42", city: "Los Angeles" } }
// 3.2 code 3 stooge["first-name"] // "Jerome" flight.departure.IATA // "SYD"
// 3.2 code 4 stooge["middle-name"] // undefined flight.status // undefined stooge["FIRST-NAME"] // undefined
// 3.2 code 5 var middle = stooge["middle-name"] || "(none)"; var status = flight.status || "unknown";
// 3.2 code 6 flight.equipment // undefined flight.equipment.model // throw "TypeError" flight.equipment || flight.equipment.model // undefined
stooge[‘first-name‘] = "Jerome"; stooge[‘middle-name‘] = "Lester"; flight.equipment = { model: "Boeing 777" }; flight.status = "overdue";
// 3.4 code 8 var x = stooge; x.nickname = "Curly"; stooge.nickname; // "Curly" var a = {}, b = {}, c = {}; // refer the diff Object a = b = c = {}; // refer the same Object
// 3.5 code 9 if (typeof Object.beget !== ‘function‘) { Object.create = function (obj) { var Func = function () {}; Func.prototype = obj; return New Func(); }; } var new_stooge = Object.create(stooge);
// 3.5 code 10 new_stooge[‘first-name‘] = ‘Harry‘; new_stooge[‘middle-name‘] = ‘Moses‘; new_stooge.nickname = ‘Moses‘;
// 3.5 code 11 stooge.profession = ‘actor‘; new_stooge.profession // ‘actor‘
// 3.6 code 12 typeof flight.number // ‘number‘ typeof flight.status // ‘string‘ typeof flight.arrival // ‘object‘ typeof flight.manifest // ‘undefined‘
// 3.6 code 13 typeof flight.toString // ‘function‘ typeof flight.constructor // ‘function‘
// 3.6 code 14 flight.hasOwnProperty(‘number‘) // true flight.hasOwnProperty(‘constructor‘) // false
// 3.7 code 15 var name; for (name in new_stooge) { if (typeof new_stooge[name] !== ‘function‘ || !new_stooge.hasOwnProperty(name)) { document.writeln(name + ‘: ‘ + new_stooge[name]); } }
// 3.7 code 16 var i; var properties = [ ‘first-name‘, ‘middle-name‘, ‘last-name‘, ‘profession‘ ]; for (i = 0; i < properties.length; i += 1) { document.writeln(properties[i] + ‘: ‘ + new_stooge[properties[i]]); }
// 3.8 code 17 new_stooge.nickname // ‘Moe‘ object‘s value delete new_stooge.nickname; new_stooge.nickname // ‘Curly‘ exposed prototype‘s value
// 3.9 code 18 var MYAPP = {};
// 3.9 code 19 MYAPP.stooge = { "first-name": "Jerome", "last-name": "Howard" }; MYAPP.filght = { airline: "Oceanic", number: 815, departure: { IATA: "SYD", time: "2004-09-22 14:55", city: "Sydney" }, arrival: { IATA: "LAX", time: "2004-09-23 10:42", city: "Los Angeles" } }
标签:
原文地址:http://www.cnblogs.com/zhangbao/p/5699279.html