利用原型写js插件
Code:
1 (function($){ 2 3 function NAME(elm,options,index){ 4 var _this = this; 5 this.$e = $(elm); 6 this.opts = options; 7 this.init(); 8 } 9 10 NAME.prototype = { 11 init : function(){}, 12 event : function(){} 13 } 14 15 $.fn.Name = function(options){ 16 var opts = $.extend({},$.fn.Name.defaults,options); 17 return this.each(function(index){ 18 this.Name = new NAME(this,opts,index); 19 }); 20 } 21 22 $.fn.Name.defaults = { 23 //默认参数 24 } 25 26 })(jQuery);