我正在尝试将方法添加到克隆的原型类属性。我已经粘贴了下面的代码。
在我向这段代码添加方法时,它会覆盖超类中定义的内容。
<script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.3/prototype.js" type="text/javascript"></script>
<script type="text/javascript">
var Animal = Class.create({
initialize: function(name, sound) {
this.name = name;
this.sound = sound;
},
speak: function() {
alert(this.name + " says: " + this.sound + "!");
}
});
Animal.movement = {
move: function(direction){
alert('moving: ' + direction)
}
}
var AnimalClone = { }
Object.extend(AnimalClone, Animal);
//Now i want to add 'jump' to this list of methods
//without over writing the inherited 'move' method
AnimalClone.movement = {
jump: function(height){
alert('jumped:' + height)
}
}
</script>