从 Javascript 中的对象继承值

Inherit the value from object in Javascript

我创建了一个动物class,它拥有动物的对象及其特征。

animal = function(){
    this.animalType = {
       tiger:{
         Character:[{
              Height: ,
              Color:'',
              Name:''
         }]
       },
       Lion:{
          Character:[{
             Height: ,
            Color:'',
            Name:''
       }]
       }
    };
};

  animal.prototype.getType = function(type){

  };

我想写一个方法来获取动物的特征 'type' 持有动物类型的密钥

这是您的动物 class 应该是什么样子的示例。 DEMO

var animal = function(o){
    this.type = o.type || 'unknown';
    this.height = o.height || -1;
    this.color = o.color || 'unknown';
    this.name = o.name || 'unknown';
}
animal.prototype.getType = function(){
    return this.type;
}

var tiger = new animal({
    type: 'tiger',
    height: 120,
    color: 'red',
    name: 'billy'
});

alert(tiger.getType());