1

Mouthful. Ok so this is the sample. I need to pass bar1 from bar2 inside a function.

var foo = { bar1 : function () { }, bar2 : function () { return function () { // bar1(); pass bar1 through here ... this.bar1 ? } } 
0

1 Answer 1

3

You can save this in variable like this:

var foo = { bar1 : function () { }, bar2 : function () { var self = this; return function () { self.bar1(); } } }; 

or use bind:

var foo = { bar1 : function () { }, bar2 : function () { return function () { this.bar1(); }.bind(this); } }; 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.