日期:2014-05-16 浏览次数:20367 次
//闭包的应用 function start(){ var count = 0; window.setInterval(function(){ document.getElementById("time").innerHTML =count; count++; },300); }; start(); //new 的真相 function Car(){ this.color = "none"; if( typeof Car._initialized == "undefined"){//定义限制第一次 Car.prototype.showColor = function(){ alert(this.color); } } Car._initialized = true; } var car = new Car(); /* new 的过程就相当于后面的操作*/ var car2 = {}; Car.call(car2); car.color = "blue"; car.showColor(); alert(car2.color); //car2.showColor(); //这个为什么调用不成功 ? 难得 new 和第二种方式还是有区别? //arguments 伪装重载 function myMethod() { alert(arguments instanceof Array); if (arguments.length == 0) { alert("no arguments"); } else if (arguments.length == 1) { alert("Hello:" + arguments[0].toString()) } } myMethod(); myMethod("ziqiu.zhang");?