jquery插件開(kāi)發(fā)
Posted on 2008-05-08 13:19 leekiang 閱讀(644) 評(píng)論(1) 編輯 收藏 所屬分類: jquery(進(jìn)去而已)1,jquery插件開(kāi)發(fā)模式
http://www.learningjquery.com/2007/10/a-plugin-development-pattern
There are a few requirements that I feel this pattern handles nicely:
(1)、Claim only a single name in the jQuery namespace
(2)、Accept an options argument to control plugin behavior
(3、Provide public access to default plugin settings
(4、Provide public access to secondary functions (as applicable)
(5、Keep private functions private
(6、Support the Metadata Plugin
(7,無(wú)論何時(shí)候,當(dāng)你的代碼出現(xiàn)each時(shí),你應(yīng)該重寫(xiě)代碼來(lái)構(gòu)造一個(gè)插件
2,jquery源碼初步研究(插件擴(kuò)展機(jī)制)
http://hi.baidu.com/uniquejava/blog/item/d55a2e12140f6953f819b821.html
3,傳入回調(diào)函數(shù)的一種寫(xiě)法,不知可有更好的
?? 傳參時(shí)的寫(xiě)法: callback:'test()'
?? 調(diào)用時(shí)的寫(xiě)法:
??? if(options.callback) eval(options.callback);
? 來(lái)源 http://www.heartstringz.net/blog/posts/view/jquery-countdown-plugin
4,(function($){
?$.fn.extend({
??????? ?plusin:function(opt,callback){
???return this;
??????? ?}
?})
})(jQuery);
?
(function($){
?$.fn.plusin = function(opt,callback){
??return this;
?}
})(jQuery);
請(qǐng)問(wèn)這兩種方式有什么區(qū)別
就這種情況而言,是沒(méi)有區(qū)別。
當(dāng)然extend有多個(gè)重載。
http://news.cnblogs.com/group/topic/2640/
http://www.learningjquery.com/2007/10/a-plugin-development-pattern
There are a few requirements that I feel this pattern handles nicely:
(1)、Claim only a single name in the jQuery namespace
(2)、Accept an options argument to control plugin behavior
(3、Provide public access to default plugin settings
(4、Provide public access to secondary functions (as applicable)
(5、Keep private functions private
(6、Support the Metadata Plugin
(7,無(wú)論何時(shí)候,當(dāng)你的代碼出現(xiàn)each時(shí),你應(yīng)該重寫(xiě)代碼來(lái)構(gòu)造一個(gè)插件
2,jquery源碼初步研究(插件擴(kuò)展機(jī)制)
http://hi.baidu.com/uniquejava/blog/item/d55a2e12140f6953f819b821.html
3,傳入回調(diào)函數(shù)的一種寫(xiě)法,不知可有更好的
?? 傳參時(shí)的寫(xiě)法: callback:'test()'
?? 調(diào)用時(shí)的寫(xiě)法:
??? if(options.callback) eval(options.callback);
? 來(lái)源 http://www.heartstringz.net/blog/posts/view/jquery-countdown-plugin
4,(function($){
?$.fn.extend({
??????? ?plusin:function(opt,callback){
???return this;
??????? ?}
?})
})(jQuery);
?
(function($){
?$.fn.plusin = function(opt,callback){
??return this;
?}
})(jQuery);
請(qǐng)問(wèn)這兩種方式有什么區(qū)別
就這種情況而言,是沒(méi)有區(qū)別。
當(dāng)然extend有多個(gè)重載。
http://news.cnblogs.com/group/topic/2640/