使用defined和require引入js
define(function(require, exports, module) { var ceshiTwo = { dataCeshi:[1,2,3,4,5], arrCeshi:function(){ var _this=this; var array=[]; $.each(_this.dataCeshi,function(key,value){ array.push(key+value); }); return array; } }; module.exports = { ceshione:ceshiTwo //向外提供ceshione的接口,该接口调用函数 //cesshiTwo }; });
其他js中调用过程:
var ceshi = require('./ceshi');
console.log(ceshi.ceshione.arrCeshi());