4

Better explained with code, is there a way around this error? Im trying to simulate a namespace.

window.SomeNamespace = {
        Notification: Backbone.Model.extend(),
        Notifications: Backbone.Collection.extend({
            model: SomeNamespace.Notification //error here. SomeNamespace is not defined
        }),
};
2
  • At the time you define the object, you cannot access itself. It does not exist yet. Commented Aug 27, 2011 at 16:55
  • On your second line Backbone.Model.extend() should probably just be new Backbone.Model Commented Sep 17, 2011 at 7:25

1 Answer 1

5

window.SomeNamespace and thus the global SomeNamespace will not be defined until the right side of the = has been executed. So you'll have to split it into two parts.

window.SomeNamespace = {
        Notification: Backbone.Model.extend(),
};


window.SomeNamespace.Notifications = Backbone.Collection.extend({
    model: SomeNamespace.Notification
});

Of course you can do it in a nicer way by using the extend() method.

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

1 Comment

I thought Backbone.Collection.extend would be generic but apparently it isn't.. so the way i used is fine.

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.