首先得用模块化的方式编写我们的js,使用define定义一个模块:
define('modelname',['jquery','xxx'], function ($,xxx) {
var hehe...},
function3: function () {
}
};
return hehe;
});
define有三个参数,第一个是模块名...上面这段代码如果用php来理解,可以看作是:
require jquery.php
require xxx.php
class hehe{
public function function1(...){
}
public function function2(){
}
}
那么我们在其他地方就可以使用这个模块:
require(['jquery', 'hehe'], function...backend', 'addtabs', 'table', 'echarts', 'echarts-theme', 'template'], function ($, undefined, Backend, Datatable