![js中使用prototype扩展对象方法 js中使用prototype扩展对象方法](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
//---------------------对象
//1.
var HomeContrl = function(){
this.foo = 'bar';
//对象方法
this.intro = function(){
alert(this.foo);
}
}
//原型方法,扩展原来对象的方法
HomeContrl.prototype.printr = function() {
alert(this.foo);
}
var obj = new HomeContrl();
var obj2 = new HomeContrl();
obj.printr();
obj2.printr();
//2.
//克隆原型BaseClass的对象方法属性的,同名对象方法不克隆
HomeContrl.prototype = new BaseClass();
//---------------------对象
//---------------------类
//类方法,扩展原类的方法,类似php中类的静态方法
HomeContrl.run = function(){
alert('i can run');
}
//---------------------类
参考http://www.cnblogs.com/yjf512/archive/2011/06/03/2071914.html