<script>
function People(){
this.action=function(){
return "Manufact";
}
this.sk="many";
this.skill=function(){
return "$"+this.sk;
}
}
//静态方法(类方法)
People.skill=function(){
return "skill :static function";
}
function BangZi(){
this.sk="paocai\zhengrong";
this.skill=function(){
return this.sk;
}
}
//理解1:BangZi把所有People的属性、方法克隆[not extend]
//理解2:Objective-C中的Category Extension
BangZi.prototype=new People();
var bz=new BangZi();
console.log(bz.action());//打印 $Manufact
//BangZi 不会扩展已拥有的同名方法或属性
console.log(bz.skill());//打印 paocai\zhengrong
//如果需要使用BangZi的实例调用People的对象方法skill,如果存在同名属性,优先使用调用者BangZi的实例的属性
var pp=new People();
console.log(pp.skill.call(bz));//打印 $paocai\zhengrong
console.log(People.skill.call());//打印 skill :static function
</script>
转载于:https://my.oschina.net/freddon/blog/494346