jeudi 23 avril 2015

How to use RequireJS properly?

I need to test a JavaScript project. There are described several modules but when I try to load them something goes wrong.

define([
  'core/BaseModel'
],

function (BaseModel) {
  var MessageModel = BaseModel.extend({
    defaults: {
      messageType: "Advertisment",
      receiver: "me",
      title: "Title",
      heading_1: "Heading1",
      heading_2: "Heading2"
    },

    url: function () {
      var base = this.apipath + '/companies/';
      if (this.isNew()) return base;
      return base + (base.charAt(base.length - 1) == '/' ? '' : '/') + this.id;
    }
  });

  return MessageModel;
});

To load the module I do this:

var message;
beforeAll(function(done){
    require(['../../../public/js/app/models/User'], function(Message){
        message = Message;
        done();
    });
});

Now message is not undefined but when I test if message.defaults or message.url is defined this fails. what is wrong there?

Aucun commentaire:

Enregistrer un commentaire