1

我有一个像这样的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函数的警报。

4

1 回答 1

2

这对我来说可以。(它提醒456

你确定一切运行正常吗?

演示:http: //jsfiddle.net/9hWAR/

演示代码:

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()
于 2013-11-14T22:16:39.750 回答