Scenario:
I got an alert()
saying undefined
when I (try to) set the myVar
variable through the Constructor. However if I uncomment the myVar
that's living inside the myView, the alert then instead says "Hello from inside", just as one would expect.
Question:
Does this mean that I cannot set any params in the constructor of the view except backbones own params, such as model
, collection
, el
, id
, className
& tagName
?
Manual: http://documentcloud.github.com/backbone/#View-constructor
The code:
var myView = Backbone.View.extend({ //myVar : 'Hello from inside', initialize: function() { alert(this.myVar); } )}; new myView({myVar: 'Hello from outside'});
Options passed into the constructor are automatically stored as this.options
var myView = Backbone.View.extend({ myVar : 'Hello from inside', initialize: function() { alert(this.options.myVar); } )}; new myView({myVar: 'Hello from outside'});
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