javascript - Thorax 2.0.1 is throwing `Cannot read property '_thoraxBind' of undefined` when constructing my View -


with following thorax 2.0.1 code:

myview = thorax.view.extend({     events: {         'foo': 'bar'     },     template: 'hello world' });  foo = new myview();  foo.bar = function() {} 

i getting following error when attempt create view:

uncaught typeerror: cannot read property '_thoraxbind' of undefined   [vm] thorax.js (849):1   _.extend._addevent                                                  [vm] thorax.js (849):1   (anonymous function)                                                [vm] thorax.js (849):1   j.each.j.foreach                                                          underscore.js:79   _.extend.on                                                         [vm] thorax.js (849):1   (anonymous function)                                                [vm] thorax.js (849):1   j.each.j.foreach                                                          underscore.js:87   h                                                                   [vm] thorax.js (849):1   at.event.configure                                                  [vm] thorax.js (849):1   (anonymous function)                                                [vm] thorax.js (849):1   j.each.j.foreach                                                          underscore.js:87   ot.view.backbone.view.extend._configure                             [vm] thorax.js (849):1   a.view                                                        [vm] backbone-min.js (848):1   ot.view.backbone.view.extend.constructor                            [vm] thorax.js (849):1   r                                                             [vm] backbone-min.js (848):1   (anonymous function)                                                             main.js:8 

here minimal reproduction.

why error occurring?

ps: can higher rep add thorax tag? thanks!

thorax requires events specified in events hash exist on object @ time of instantiation. there 2 possible solutions:

add function before object instantiation

// add 'bar' function object before instantiation myview = thorax.view.extend({     events: {         'foo': 'bar'     },     template: 'hello world' });  myview.prototype.bar = function() {}  foo = new myview(); 

use anonymous function wrap call

if dynamically adding function @ later time, can following:

// wrap call this.bar in anonymous function satisfy thorax myview = thorax.view.extend({     events: {         'foo': function(e) { this.bar(e); }     },     template: 'hello world' });  foo = new myview();  foo.bar = function() {} 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -