<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>继承</title> </head> <body> <script> function A(){ this.abc = 12; } A.prototype.show = function(){ alert(this.abc); } function B(){ A.call(this);//call把B里面的this赋值给了A } //B.prototype = A.prototype;//这样写会进行地址引用,如果再对B进行操作时,A也会发生变化 for(var i in A.prototype){ B.prototype[i] = A.prototype[i]; } B.prototype.fn = function(){ alert("ABC"); } A.fn(); var obj = new B(); alert(obj.abc); </script> </body> </html>