<!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>
?