jQueryのプラグインの第一歩。 2013/11/01

jQueryのプラグインの第一歩。
呼び出すとき$.plugIn.xxx()でいけるのかなと思ってたのだけど、$().plugIn.xxx()として動かせた。自分勉強不足だなー。

(function($) {
    $.fn.myPlugin = function( option ) {
        return this.each(function() {
        });
    };
    $.extend($.fn.myPlugin , {
        aaa : function(){ alert(this);  },
        bbb : function(){ alert("bbb"); }
    });
})(jQuery);


$(document).ready( function(){
    $().myPlugin.aaa();
    $().myPlugin.bbb();
    console.log("*** this line OK");
});

: