一、对象的继承,通常的作法是复制:Object.extendhtml
prototype.js的实现方式是:数组
Object.extend = function(destination, source) { for (property in source) { destination[property] = source[property]; } return destination; } |
除此以外,还有种方法,就是:Function.apply(固然使用Function.call也是能够的)app
apply方法能劫持另一个对象的方法,继承另一个对象的属性ide
Function.apply(obj,args)方法能接收两个参数函数
obj:这个对象将代替Function类里this对象post
args:这个是数组,它将做为参数传给Function(args-->arguments)性能
apply示范代码以下:this
<script> function Person(name,age){ //定义一个类,人类 this.name=name; //名字 this.age=age; //年龄 this.sayhello=function(){alert("hello")}; } function Print(){ //显示类的属性 this.funcName="Print"; this.show=function(){ var msg=[]; |