日期: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
1楼han_yankun20093天前 08:35
学习了