JavaScript: Pass value of x into function

How can I pass on the value of x into this function?

var x = 'Hello';
marker.events.click = function() {alert(x) }

Open in new window

LVL 16
hankknightAsked:
Who is Participating?
 
Meir RivkinConnect With a Mentor Full stack Software EngineerCommented:
Sorry my mistake, u need to assign x to 'this' variable:
var me = this;
var x = 'Hello';
me.x=x;
marker.events.click = function() {alert(me.x); }
0
 
Meir RivkinFull stack Software EngineerCommented:
var me = this;
var x = 'Hello';
marker.events.click = function() {alert(me.x); }
0
 
hankknightAuthor Commented:
That does NOT work.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.