`
tonynju
  • 浏览: 74390 次
  • 性别: Icon_minigender_1
  • 来自: 浙江嘉善
社区版块
存档分类
最新评论

javascript继承和Ext继承小记

阅读更多
Rectangle类的定义以及子类Square的定义

var Rectangle = function(config){
    
    //console.log( this)


    this.width = config.width;
    this.height = config.height;

    //console.log( this)
}
Rectangle.prototype = {
    name: '',
    getArea: function(){
        return this.width * this.height;
    },
    getWidth: function(){
        return this.width;
    }
}

var rec = new Rectangle({width: 100, height: 200});

//console.log( rec )

var area = rec.getArea();

Square = function(config){

    this.width = config.edage;
    this.height = config.edage;

}

Square.prototype = new Rectangle({width:1, height:1})
Square.prototype.getA = function(){
    return 'A';

}

var s = new Square({edage: 40})

console.log( s.getArea() )

if(s instanceof Rectangle){
    console.log( 'success' )
}


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics