Javascript: Passing 'this' to inline function

Skip Navigation LinksIrocon > Blog > 2008 > March, 2008 > March 20, 2008 > Javascript: Passing 'this' to inline function

Javascript: Passing 'this' to inline function

Create a new variable within the parent function:

var me = this;
use 'me' in new function

Example:

 

 function parentFunction() {

 this.message = 'Hello World!';
 var me = this;
 var childFunction = function() {
   alert(me.message);
 }

 childFunction();

}

Last Updated:Thursday, September 02, 2010By:alfero#

Would you like to comment?

Sign in with your OpenID. If you do not know what OpenID is, find out.