javascript - Marionette. Add methods to view via behaviors -
so have:
- class
mysuperbehavior
extendsmarionette.behavior
- bunch of classes extends
marionette.itemview
, usesmysuperbehavior
,tralalaview
,trololoview
etc
i want create method mysuperbehavior every instance of tralalaview , trololoview can use. how can correctly?
sample code illustrate:
var mysuperbehavior = marionette.behavior.extend({ awesomenonstaticmethod: function(){ console.log(this); } });
we suppose correct linking of classes
var tralalaview = marionette.itemview.extend({ behaviors: { somebehavior: { behaviorclass: mysuperbehavior } } // methods here }); var instoftralala = new tralalaview(); console.log(instoftralala.awesomenonstaticmethod()); // want
i did that:
var mysuperbehavior = marionette.behavior.extend({ initialize: function(options, view){ this.view.awesomenonstaticmethod = this.awesomenonstaticmethod } awesomenonstaticmethod: function(){ console.log(this); } });
Comments
Post a Comment