2

That how I usually implement my plugins:

(function($){
    $.fn.plugingName = function(inSettings){
        //code that extands settings with default
        return this.each(function(){
        new PluginClass($(this), settings);
        });
    }

    PluginClass = function(jElem, settings){
        //here I usually put variable and function in such a way to compose better
        var events = {
            onMouseUp : function(){
                //some actions
            },
            onMouseMove : function(event){
                //some actions
            }, 
            //etc.
        },
        draw = {
            drawGrid : function(){//some actions},
            //etc.
        },
        //etc.

        /*****************************
         * This is a place of question
         ****************************/ 
    }
})(jQuery);

I just want to know if there is a pattern to separate the algorithm from declaration part that I described above. Some thing like to put all your algorithm part inside

function main(){
}();

If there is a better approach to distinguish the main part of your algorithm. I hope I described everything clear.

All others improvment that might be done with represented code are also appreciate.

1 Answer 1

1

You mean putting the function main() outside of the big wrapping function($){ ...? But this is not desired, the wrapping function is there for the very reason not to overcrap the global namespace. This is the very clean design and it is desired. So don't be worry to use this standard pattern.

Sign up to request clarification or add additional context in comments.

1 Comment

Not really. I'm saying to put main (or another approuch) to 'This is a place of question' comment. I want to separate declaration and implementation part form the entry point, to emphasize the begining of algorithm. Something like main function in C/C++/Java etc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.