js中prototype的继承和扩展

来源:互联网 发布:网络代理服务器 编辑:程序博客网 时间:2024/04/26 22:57
<html><script>/*继承function Person(name,age){this.name=name;this.age=age;this.say=function(){alert('say....');}}function Boy(){}Boy.prototype=new Person('z3',20);var b=new Boy();alert(b.name);alert(b.age);b.say();function Person(name,age){this.name=name;this.age=age;this.say=function (){alert('say.....');}}function Boy(){}Boy.prototype=new Person('z3',20);var b=new Boy();alert(b.name);alert(b.age);b.say();*///prototype继承和扩展function Person(name,age){this.name=name;this.age=age;this.say=function(){alert('say....');}Person.prototype.id=1;Person.prototype.method=function(){alert('ext method');}function Boy(name,age){}Boy.prototype=new Person('w5',20);var b=new Boy();alert(b.name);alert(b.age);b.say();alert(b.id);b.method();}</script></html>