Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 超越原型方法_Javascript - Fatal编程技术网

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

我有这样一个javascript基函数

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谢谢,那么:-)唯一要做的就是用更完整的代码提出一个新的问题。不,没关系,我只需要确保调用的是我期望调用的对象,也许还需要重新访问我的对象层次结构。