基本的用法 把ClassA的一个实例赋值给ClassB ClassB就继承了ClassA的所有属性
<script> function ClassA() { this.a='a'; } function ClassB() { this.b='b'; } ClassB.prototype=new ClassA(); var objB=new ClassB(); for(var p in objB)document.write(p+"<br>"); </script>
<script> function ClassA() { this.a='a'; } function ClassB() { this.b='b'; } ClassB.prototype=new ClassA(); var objB=new ClassB(); alert(objB.a); ClassB.prototype.a='changed!!'; alert(objB.a); </script>
<script> function ClassA() { this.a='a'; } function ClassB() { this.b='b'; } ClassB.prototype=new ClassA(); var objB1=new ClassB(); var objB2=new ClassB(); objB1.a='!!!'; alert(objB1.a); alert(objB2.a); </script>
<script> function ClassA() { this.a=function(){alert();}; } function ClassB() { this.b=function(){alert();}; } ClassB.prototype=new ClassA(); var objB1=new ClassB(); var objB2=new ClassB(); alert(objB1.a==objB2.a); alert(objB1.b==objB2.b); </script>
<script> function ClassA() { alert("a"); this.a=function(){alert();}; } function ClassB() { alert("b"); this.b=function(){alert();}; } ClassB.prototype=new ClassA(); var objB1=new ClassB(); var objB2=new ClassB(); </script>
<script> function ClassA() { this.a=[]; } function ClassB() { this.b=function(){alert();}; } ClassB.prototype=new ClassA(); var objB1=new ClassB(); var objB2=new ClassB(); objB1.a.push(1,2,3); alert(objB2.a); //所有b的实例中的a成员全都变了!! </script>