0

I'm having trouble including a module in RequireJS.

There's two files.. test.js and card.js

In test.js, when the page loads it says "undefined is not a function":

require(
    ['app', 
     'jquery', 
     'card'], 
    function(App, $, Card) {
        var card = new Card("test");
    }
);

Here is the card.js:

define("Card", function () {
    function Card(name) {
       this.name = name;             
    };

    return Card;
});

I put some console.log()'s in the card.js and it calls those fine when it's being referenced like that in test.js. Also if I were to define a regular js object class in card.js (e.g.):

function Card(name) {
   this.name = name;
}

I am able to create that Card object properly in test.js.

Any clues how I'm hooking it all up wrong?

5
  • 1
    Click on the link at the right of the "undefined..." message in your inspector, it will show you the line it is breaking at. Commented May 24, 2014 at 16:18
  • It is breaking at this line: var card = new Card("test"); Commented May 24, 2014 at 16:22
  • Well, then you're obviously not "able to create that Card object properly". Commented May 24, 2014 at 17:35
  • 1
    Hint: your module names are not the same. Not sure whether require handles them case-insensitive and why it does not grump about that. Commented May 24, 2014 at 17:37
  • I was able to create a card object, just not through modules. It turned out to be a case sensitivity issue. Thanks. Commented May 24, 2014 at 18:45

1 Answer 1

1

The problem, as Bergi said, is that your module names are not the same.

To RequireJS, Card and card are different modules.

All you have to do is change card.js to

define("card", function () {
    function Card(name) {
       this.name = name;             
    };

    return Card;
});
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.