拷贝继承
<!doctype html> <html> <head> <meta charset="utf-8"> <title></title> <style> </style> </head> <body> <script type="text/javascript"> function A() { this.abc = 12 alert(this.abc); } A.prototype.show = function() { alert(this); } //new A().show(); //(new A).show(); function B() { //此时this => new B(); A.call(this); } for(var i in A.prototype)//让B拷贝A的属性 { B.prototype[i]=A.prototype[i]; } var obj = new B(); alert(obj.abc); </script> </body> </html>

浙公网安备 33010602011771号