RT,领导让我把网站用到的javascript包装成框架,有什么思路吗?
封装成库吧,框架这东西太难了。简单点无脑就是吧所有逻辑全放在一个对象里面。
比如
(function($){
var methods = {
method1: function(options) {},
method2: function() {},
method3: function(args) {}
};
jQuery.fn.myObj = function(method) {
if(methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if(typeof method === 'object' || !method) {
return methods.method1.apply(this, arguments);
} else {
$.error('Method' + method + 'does not exist on jQuery.myObj');
}
}
})(jQuery);
复杂一点就要分层,核心代码Core,数据处理代码Data,UI等Interface分开处理。
13 回答13k 阅读
7 回答2.2k 阅读
3 回答1.3k 阅读✓ 已解决
6 回答1.3k 阅读✓ 已解决
2 回答1.4k 阅读✓ 已解决
3 回答1.3k 阅读✓ 已解决
6 回答1.1k 阅读
搜索“制作jq插件”