1

I have created module

myModule.js

require(['jquery'],function($){
    return {
        init: function(){
            $('.test').hide();
        }
    }
});

config:

require.config({
    baseUrl : "js/",
    paths : {
        jquery : 'lib/jquery/jquery-2.1.1',
        myModule : 'lib/modules/myModule
    },
    shim : {

    }
});

Now I want to use mymodule.init function in other module in proper place (lets say after AJAX load)

require(['jquery', 'myModule'],function($, myModule){
    ...
        myModule.init();
    ...
});

Here I have an error:

Cannot read property 'init' of undefined 

What I did wrong?

1 Answer 1

1

In myModule.js you call require. You should call define instead so that your module is defined. A define call with a first argument that is a dependency list and a second argument that is a function is somewhat like a require call with the same arguments but additionally defines your module.

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

1 Comment

Stupid mistake. Thanks :)

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.