1、原型链继承 javascript
function Parent(){} function Child(){} Child.prototype = new Parent();
经过对象child的prototype属性指向父对象parent的实例,使child对象的实例经过原型链访问到父对象构造所定义的属性、方法等。java
2、使用apply、call方法 数组
js中call和apply均可以实现继承,惟一的一点参数不一样,func.call(func1,var1,var2,var3)对应的apply写法为:func.apply(func1,[var1,var2,var3])。app
相同点:第一个参数this都同样,指当前对象。this
不一样点,第二参数不同,call是一个个的参数列表,apply是一个数组(arguments也能够)spa
<script type="text/javascript"> function Person(name,age,love){ this.name=name; this.age=age; this.love=love; this.say=function say(){ alert("姓名:"+name); } } //call方式 function student(name,age){ Person.call(this,name,age); } //apply方式 function teacher(name,love){ Person.apply(this,[name,love]); //Person.apply(this,arguments); //跟上句同样的效果,arguments } //call与aplly的异同: //1,第一个参数this都同样,指当前对象 //2,第二个参数不同:call的是一个个的参数列表;apply的是一个数组(arguments也能够) var per=new Person("武凤楼",25,"魏荧屏"); //输出:“武凤楼” per.say(); var stu=new student("曹玉",18);//输出:“曹玉” stu.say(); var tea=new teacher("秦杰",16);//输出:“秦杰” tea.say(); </script>
3、对象实例间的继承 .net
原文来自:http://www.jb51.net/article/20431.htmprototype