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' )
}


你可能感兴趣的:(JavaScript,ext,prototype)