標籤:
//方法一:將函數綁定到原型上define(function(require, exports, module) { $.fn.tab = function(option, callback) { function bootstrap() { console.log(‘djsakhdkj‘); } bootstrap(); } $(function(){ $().tab();//因為將tab綁定到$原型上,所以要使用$().tab()去調用 })})
//方法二:直接寫函數形式define(function(require, exports, module) { var tab = function(option, callback) { function bootstrap() { console.log(‘545‘); } bootstrap(); } $(function(){ tab();//因為將tab綁定到$原型上,所以要使用$().tab()去調用 })})
上面對應的html中調用:
seajs.use(‘./../../js/tab‘);
第三種方法:
//方法三:使用module.exports向外提供函數介面,html中代碼為:// seajs.use(‘./../js/calendar‘, function () {// init();// });define(function(require, exports, module) { $.fn.tab = function(option, callback) { function bootstrap() { console.log(‘djsakhdkj‘); } bootstrap(); } $(function(){ init=function(){ $().tab();//因為將tab綁定到$原型上,所以要使用$().tab()去調用 } module.exports=init; })})
對應的html檔案:
seajs.use(‘./../js/calendar‘, function () { init(); });
使用seajs編寫模組