自定义jquery插件

    xiaoxiao2021-12-14  18

    /*$.fn.mytable将这个函数写到了prototype里面去了。 原来 jQuery.fn = jQuery.prototype.对prototype肯定不会陌生啦*/ /*(function($){...})(jQuery)、(function(arg){})(param)、(function(){})()------函数的自执行都是是匿名函数,function($){...}参数为$、function(arg){...}参数为arg,function(){...}无参。*/ /*简单理解是(function($){...})(jQuery)用来 定义 一些需要预先定义好的函数,这种匿名函数写法的最大好处是形成闭包,使得在(function($) {…})(jQuery)内部定义的函数和变量只能在此范围内有效。*/ if(typeof Object.create!="function"){//IE等浏览器不支持Object.create,就有了这段代码手动添加这个方法 Object.prototype.create=function(obj){ var F=function(){}; F.prototype= obj; return new F(); } } (function($,window,document){ // 创建对象,通过基于对象的继承的方式 var Mytable={ init:function(){ this.prop="value"; } }; $.fn.mytable=function(){console.log("is ok"); var mytable=Object.create(Mytable);//这里可以理解为上面的Mytable为一个类,在这里mytable继承了MyTable这个类。 console.log(Mytable);console.log(mytable); mytable.init();//调用init方法 console.log(mytable); }; $.fn.mytable.options={width:700,headBg:true,evenBg:true,hoverBg:true}; })(jQuery,window,document);

    转载请注明原文地址: https://ju.6miu.com/read-972237.html

    最新回复(0)