读书人

javascript10.0(承继)

发布时间: 2012-09-15 19:09:29 作者: rapoo

javascript10.0(继承)
17. JavaScript中的继承。
1) 对象冒充

<html><head><script type="text/javascript">function Parent(hello) {this.hello = hello;}Parent.prototype.sayHello = function() {alert(this.hello);}function Child(hello, world) {Parent.call(this, hello);this.world = world;}Child.prototype = new Parent();Child.prototype.sayWorld = function() {alert(this.world);}var child = new Child("hello", "world");child.sayHello();child.sayWorld();</script></head><body></body></html>

读书人网 >JavaScript

热点推荐