Backbone.js - passing arguments through constructors

后端 未结 2 730
野趣味
野趣味 2021-02-01 15:54

Scenario:
I got an alert() saying undefined when I (try to) set the myVar variable through the Constructor. However i

2条回答
  •  隐瞒了意图╮
    2021-02-01 16:19

    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'});
    

提交回复
热议问题