function ClassB(sColor, sName){
ClassA.call(this,sColor);
this.name=sName;
this.sayName=function(){alert(this.name);};
}
其中ClassA.call(this,sColor)中的this,只的是ClassA还是ClassB?为什么
ClassA.call(this,sColor);
this.name=sName;
this.sayName=function(){alert(this.name);};
}
其中ClassA.call(this,sColor)中的this,只的是ClassA还是ClassB?为什么
<html>
<head>
<title>e </title>
<script>
function ClassA(color){
this.color = color;
}
function ClassB(name,color){
ClassA.call(this,color);
//对象1.call(对象2,参数)是对象1代替对象2执行 对象1(参数),这里就是ClassA(color),即this.color=color;因此这里this指ClassB
//call常用于继承,这里B就继承了A
this.name = name;
}
var B = new ClassB("lz","red");
alert(B.name+" "+B.color);
</script>
</head>
<body>
</body>
</html> http://hi.baidu.com/o886/blog/item/ea5dfefda513041e08244d61.html
这里解释的比较详细,lz可以看看