javascript_call1实现的继承
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>js01_hello</title> <meta name="author" content="Administrator" /> <script type="text/javascript"> function Parent() { this.color = ["red","blue"]; this.name = "Leon"; } function Child() { //在Child中的this明显应该是指向Child的对象 //当调用Parent方法的时候,而且this又是指向了Child //此时就等于在这里完成this.color = ["red","blue"] //也就等于在Child中有了this.color属性,这样也就变相的完成了继承 Parent.call(this); //这种调用方式,就仅仅完成了函数的调用,根本无法实现继承 //Parent(); } var c1 = new Child(); c1.color.push("green"); alert(c1.color); var c2 = new Child(); alert(c2.color); alert(c2.name); </script> </head> <body> </body> </html>