_.bindAll() on JavaScript singleton methods?

martinant

New Member
The method obj2.method1, in the code below, is called from another object.How do I bind the "this context" so that I can refer to obj1 from obj2?\[code\]var singleton = { obj1 : { a : 5 }, obj2 : { method1 : function(){ this.obj1.a; //undefined } }}\[/code\]I tried using underscore _.bindAll() - something along these lines - but failed ...\[code\]var singleton = { obj1 : { a : 5 }, obj2 : { method1 : function(){ this.obj1.a; //undefined } }, init : function(){ _.bind(this, obj2.method1) }}singleton.init();\[/code\]Thanks :)
 
Top