Im looking at some Backbone.js examples and they have var app = app || {};
at the top of all .js files. I understand the literal meaning of this, but what does it do in reference to everything else?
Edit: you guys are really really fast.
It will define the variable app
to an empty object if it is not already defined.
This works because being undefined evaluates to false
in Javascript.
If it is defined, it may still be re-defined as an empty object if it has a value which evalutes to false
, such as an empty string.
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