function Person( name, age ){
this.name = name;
this.age = age;
this.sleep = function(){
alert( this.name + "is sleepping....zzzz");
}
}
function worker( name, age, company, job ){
Person.apply( this, arguments);
this.company = company;
this.job = job;
this.work = function(){
alert( this.name + " is working in " + this.company);
}
}
var cl = new worker( "chenliang", 27, "baidu", "FE" );
cl.work();
cl.sleep();
当看apply的应用的时候,想到面向对象的设计思想。个人,面向对象的设计思路对代码的重复利用很有帮助,但是,在前端的开发过程中,每个模块都是独立并个性多共性少的。所以,不是很明白,在前端开发中,使用面向对象的设计思路,除了代码结构清晰之外还有什么好处。而且对象属性和方法的读取性能要低于局部变量的读取性能。