JavaScript里没有继承关键字,想要继承一个类需要用到“对象冒充”。5 W4 q0 h0 `: Y7 v# G# R: v1 m
<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>
$ s* z, _" ~3 e. m7 Q U7 R1 r# j8 ^: y6 P" `
|