标签:style blog io color sp on div log cti
原型中的方法是共享的,如果每次创建构造函数时不必在重新在原型中添加方法
function Person(name,age){ this.name = name; this.age = age; //方法 if(typeof this.sayName != "function") { Person.prototype.sayName = function(){ alert(); }; } }
这样在new Person时 sayName方法就不必每次都重新创建。
标签:style blog io color sp on div log cti
原文地址:http://www.cnblogs.com/lcw5945/p/4142477.html