I'm working on a backbone application.
I've structured my models + collections + views in different files.
which means a solution like
function() { // all my code }()
doesn't apply here
I added a namespace e.g
App.ModelName App.Views.ViewName etc.
when I'm within the same namespace. How can I avoid repeating it. i.e how can I call ModelName when I'm in a function defined in App.Views.ViewName
at the moment I keep repeating the full string i.e App.XXXX
Thanks
You have several choices:
1) Create a local variable in each function:
App.ModelName.myFunction = function() {
var model = App.ModelName;
// then you can reference just model
model.myFunction2();
}
2) Create a local variable in each file scope:
(function() {
var model = App.ModelName;
model.myFunction = function() {
// then you can reference just model
model.myFunction2();
}
// other functions here
})();
3) Use the value of this
:
App.ModelName.myFunction = function() {
// call App.ModelName.myFunction2() if myFunction() was called normally
this.myFunction2();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With