jQuery: Module Stub

jQuery module stub with basic namespace and function declarations. Not sure if this is the right way to do it. YMMV.

// usage $("selector").moduleStub(options);
(function ($) {
    $.fn.moduleStub = function (options) {
        return inlineEditor.init(this, options);
    };
})(jQuery);

var moduleStub = {
    el: {},
    options: {},
    init: function (el, options) {
        this.el = $(el);
        if (options) { $.extend(this.options, options); }
        return this;
    },
    test: function () {
        alert(this.el.attr("id"));
    }
}

0 comments: