我一直在玩Screeps已经有一段时间了,昨晚我决定通过从Creep主类派生两个类Miner和Transporter来将我的一些行为变成类层次结构.但是,每当我这样做
console.log(_.functions(minerInstance));
Run Code Online (Sandbox Code Playgroud)
我得到的功能列表和我一样
console.log(_.functions(transporterInstance));
Run Code Online (Sandbox Code Playgroud)
有人能告诉我,如果我做错了或者我实际上遇到了我的代码运行的环境限制吗?这是我的代码:
////////////////////////////
// Creep.js
var Creep = function(creep, room) {
this.creep = creep;
this.room = room;
this.name = creep.name;
this.id = creep.id;
};
module.exports = Creep;
Creep.prototype = {
tick: function() {
console.log("Base class implementation of tick(), should never happen.");
},
getRole: function() {
return this.creep.memory.role;
}
};
////////////////////////////
// Miner.js
var Creep = require("Creep");
var Miner = function(creep, room) {
this.base = Creep;
this.base(creep, room);
//Creep.call(this, creep, room);
};
module.exports = Miner;
Miner.prototype = Creep.prototype; …Run Code Online (Sandbox Code Playgroud)