0

what is the correct syntax to create a namespace within jquery, so as to allow the passing of the matched set to nested methods?

this is what I have:

(function($) {
    var nameSpace = {
        module: function(x){

        }
    }
})(jQuery)

but calling $('.selector').nameSpace.module() returns

Cannot call method 'module' of undefined

1 Answer 1

1

This will not work as you have not added anything to jQuery.fn, which is where all plugins get added. You will likely run into issues even if you did this though as jQuery does some fancy things with how this is bound.

If you wish to have multiple methods on a single plugin i would suggest reading through the jQuery documentation on namespacing plugins

Hope that helps

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

Comments

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.