JavaScript里没有继承关键字,想要继承一个类需要用到“对象冒充”。6 i' a1 T! E: W+ _( I+ N
<script type = 'text/javascript'>
function Person(name , age){
this.name = name ;
this.age = age ;
this.say = function (){
return "name : "+ this.name + " age: "+this.age ;
} ;
}
var o = new Object() ;//可以简化为Object()
Person.call(o , "zhangsan" , 20) ;
console.log(o.say() );//name : zhangsan age: 20
</script>
2 o0 t* |9 x( a& M d
* I! l' ` n& a# Z9 G' G |