日期:2014-05-16 浏览次数:20346 次
<script type="text/javascript">?
function classA(sColor){
??? this.color=sColor;
??? }
classA.prototype.sayColor=function(){
??? alert(this.color);
??? }???
function classB(sColor,sName){
??? classA.call(this,sColor);//用对象冒充继承构造函数的属性
??? this.name=sName;
??? }???
classB.prototype=new classA();
classB.prototype.sayName=function(){//用原型链继承prototype对象的方法
??? alert(this.name);
??? }
???
var A=new classA("red");
A.sayColor();
var B=new classB("blue","Joan");
B.sayName();
B.sayColor();
</script>