自定义jquery插件

/*$.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);


这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值