日期:2014-05-16 浏览次数:20453 次
var obj = {};// 空对象 var ref = obj;// 引用 obj.name = "objectA"; alert(ref.name);// "objectA" obj = ["one", "two", "three"];// obj指向了另一个对象 alert(ref.name);// "objectA" alert(obj.length);// 3 alert(ref.length);// undefined
var triangle = new Shape("triangle",23);
var triangle = {}; Shape.apply(triangle, ["triangle",23]);
var adder = function(num) { return function(y) { return num + y; } } var inc = adder(1); var dec = adder(-1); alert(inc(99));// 100 alert(dec(101));// 100 alert(adder(100)(2));// 102 alert(adder(2)(100));// 102
var base = { name : "base", getInfo : function() { return this.name; } } var ext1 = { id : 0, __proto__ : base } var ext2 = { id : 9, __proto__ : base } alert(ext1.id); alert(ext1.getInfo()); alert(ext2.id); alert(ext2.getInfo());