Answer the question
In order to leave comments, you need to log in
How to encapsulate in backbone?
When creating models, views, collections, we create them in the global scope, is that bad?
How to encapsulate all this but at the same time so that different application modules have access to each other, can communicate?
For example, this is how I can hide all the code from the global scope
(function(Backbone,_){
var User = Backbone.Model.extend({
defaults:{
name:'user',
login:'почта не указана',
pass: 'пароль не указан'
},
validate:function(attr){
if(name.length < 3){
return 'Имя содержит слишком мало символов!';
}
}
});
var user = new User({name:'Vasia',login:'[email protected]',pass:'root'});
})(Backbone,_);
Answer the question
In order to leave comments, you need to log in
Discover a real modular system - Require.JS or Browserify . The first is more flexible, but does not require a compilation step, the second has more plugins and has less overhead.
PS For good, it is already possible (and even necessary) to start writing in ES2015 and use local modules and other goodies.
Use Marionette , it has a module system and many other useful things.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question