Auto Properties

I am building an application using Backbone which follows below:

App = {
  Models: {},
  Views: {},
  Collections: {},
  Routers: {}
};

When designing an object - in this case, view -, I do the following:

App.Views.ProductsView = Backbone.Model.extend();

But I need something like:

App.Views.Products.IndexView = Backbone.Model.extend();

What a big deal?

If I previously announced App.Views.Products = {}, everything will work, but I want to do it automatically; without any previous declaration.

Based on my problem, can you give me an idea?

+4
source share
2 answers

I'm not sure I get it, but did you declare a property before adding properties to the chain?

App.Models.Products = {};

App.Models.Products.IndexView = Backbone.Model.extend();

Of course, you can declare it in several ways, for example, when creating an application.

App = {
  Models      : {
        Products : {} // here
  },
  Views       : {},
  Collections : {},
  Routers     : {},
  Views       : {}
};

or as a literal containing a key, etc.

App.Models.Products = {
    IndexView : Backbone.Model.extend();
}

, javascript , .

+6

App.Views.Products = {}, - ; - .

, , " ":

App.Views.Products = App.Views.Products || {}; 

, .

0

All Articles