---
title: "javascript继承和Ext继承小记"
author: "tonynju"
date: "2009-08-08T17:48:05Z"
tags: []
slug: "javascript-ext"
draft: false
lastmod: "2009-08-08T17:48:05Z"
id: 442978
url: "https://tonynju.iteye.com/blog/442978"
---

Rectangle类的定义以及子类Square的定义


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

```