我有一个像这样的 javascript 基本函数;
roomBase = function () {
this.go = function(){
alert(1);
}
}
我有一个这样的房间对象;
myRoom = function(){
this.go = function(){
alert(456);
}
}
myRoom.prototype = new roomBase();
theRoom = new myRoom();
当我调用 theRoom.go()
时,我收到来自 prototype
的警报。我想要的是来自 myRoom
函数的警报。
最佳答案
它对我来说很好用。 (它提醒 456
)
您确定一切正常运行吗?
演示代码:
var roomBase = function () {
this.go = function(){
alert(1);
}
}
var myRoom = function(){
this.go = function(){
alert(456);
}
}
myRoom.prototype = new roomBase();
var theRoom = new myRoom();
theRoom.go()
关于javascript - 覆盖原型(prototype)方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19989556/