Javascript 超越原型方法
我有这样一个javascript基函数Javascript 超越原型方法,javascript,Javascript,我有这样一个javascript基函数 roomBase = function () { this.go = function(){ alert(1); } } myRoom = function(){ this.go = function(){ alert(456); } } myRoom.prototype = new roomBase(); theRoom = new myRoom(); 我有一个像这样的房间物体 roomBase = function
roomBase = function () {
this.go = function(){
alert(1);
}
}
myRoom = function(){
this.go = function(){
alert(456);
}
}
myRoom.prototype = new roomBase();
theRoom = new myRoom();
我有一个像这样的房间物体
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()
直到我看到你的手我才明白。让我再仔细看看。thanksNo problem@griegs您的代码中可能有一个错误,而不是OP+1中的错误。您完全正确。我想我现在可能调用了错误的对象,这会引发更多的问题。@griegs谢谢,那么:-)唯一要做的就是用更完整的代码提出一个新的问题。不,没关系,我只需要确保调用的是我期望调用的对象,也许还需要重新访问我的对象层次结构。