0

I have been defining my controllers like this for a while(without any lib) but the dependencies drove me crazy and now I'm trying to integrate requireJs.

controller = new function () {

    this.test = "Hello World";

    this.__construct = function () {
       alert(this.test);
    };

    this.__construct();

};

How can one transform this to a requireJs Module? I have tried the following

define(function () {

   return controller = new function () {

       this.test = "Hello World";

       this.__construct = function () {
           alert(this.test);
       };

       this.__construct();
    };

});

Could I simply do ?

define(controller);

In My Main

//main.js
requirejs(['controller']);

However, the alert popup wont show up.

1 Answer 1

1

Your controller definition should be okay - however, you're misusing require in your main.js:

//main.js
requirejs(['controller'], function(controller){
    // use controller here
});
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.