Not defined error when using javascript objects
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 开发者_Python百科//error here. SomeNamespace is not defined
}),
};
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.
精彩评论