开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜