首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

javascript继承父类属性数组有关问题

2012-10-08 
javascript继承父类属性数组问题extend-array.png 扩展名改为htm即可?注:父类属性是对象时可采用深度克隆

javascript继承父类属性数组问题

extend-array.png 扩展名改为htm即可

?

注:父类属性是对象时可采用深度克隆的方式

?

?<html>
? <body>
? <script>
? ??? function A(){
? ??? ??? this.list = [1,2,3];
? ??? ??? this.elem = {a:1,b:2};
? ??? }
? ??? function B(){
? ??? ??? this.list = new Array(B.prototype.list);
? ??? ??? this.elem = new Object(B.prototype.elem);
? ??? }
? ??? B.prototype=new A();
? ??? B.constructor=B;
? ???
? ??? var a1 = new B();
? ??? var a2 = new B();
? ???
? ??? a1.list.push(123);
? ??? a1.elem.a=3;
? ??? alert(a2.list);
? ??? alert(a1.list);
? ??? alert(a2.elem.a);
? ??? alert(a1.elem.a);
? ???
? ???
? </script>
? </body>
</html>

热点排行