- 爱易网页
-
JavaSript
- js承袭
日期:2014-05-16 浏览次数:20451 次
js继承
1、prototype方式
var BaseClass = function ()
{
this.name = "3zfp";
this.age = 100 ;
this.ToString = function (){return this.name + " " + this.age;}
}
var Derived = function ()
{
this.address = "ShenZhen";
}
Derived.prototype = new BaseClass();
var instance = new Derived();
instance.ToString();
2、apply方式
var BaseClass = function ()
{
this.name = "3zfp";
this.age = 100;
this.ToString = function(){return this.name + " " + this .age;}
}
var Derived = function ()
{
BaseClass.apply(this,new Array());
this.address = "ShenZhen" ;
}
var instance = new Derived();
instance.ToString();
3、call+prototype 方式
var BaseClass = function(name,age)
{
this.name = name;
this.age = age;
this.ToString = function(){return this .name + " " + this.age;}
}
var Derived = function()
{
BaseClass.call(this,"3zfp",100);
this.address = "ShenZhen";
}
Derived.prototype = new BaseClass();
var instance = new Derived();
instance.ToString();
引用地址:http://cache.baidu.com/c?m=9f65cb4a8c8507ed4fece763105392230e54f733628a854d2c90c05f93130716017bb3e87a69435393d82f2747f41802bdb12b71350426bd98df883d87fdcd763bcd7a742613de0005d368b8bb3732b051872ae8b86fe5&p=8d3dd71386cc42af5dfce62d021dcf&user=baidu&fm=sc&query=js+%BC%CC%B3%D0&qid=920dcd5801261263&p1=8
免责声明: 本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。