JS引入其他文件
1.在cocos2dx-js中require可直接 引入
var js_list = [ "src/AudioMgr.js", "src/MapStack.js", "src/MapData.js", "src/MapUI.js" ]; function initJSFile() { for (var i in js_list) { require(js_list[i]); } };
AudioMgr.js: var AudioMgr = { PlaySound_Move: function () { cc.audioEngine.playMusic(res.sound_move, false) }, PlaySound_Over: function () { cc.audioEngine.playMusic(res.sound_over, false) } }
2.在Node.js中需要这样引用
app.js: var Person1 = require("./Person.js") var a = new Person1(); a.age = 100; a.Print() var b = new Person1; b.Print(); Person.js: var Person = function () { this.name = "hk"; this.age = 20; }; Person.prototype.Print = function () { console.log("name = " + this.name + " age = " + this.age); }; module.exports = Person; //导出