ezhil ezhil - 2 years ago 63
Javascript Question

Set variable to function but that function should not get executed

I am setting some variable in someMethod1 and want to pass that variable to someMethod2. Here I just want to set variable to someMethod2 function but that method should not get called. It needs to be called later on some event(click). How can I achieve this one? Please help me.

someMethod1 = function() {
var test = "testText";

someMethod2 = function(check) {
var a = check;

Zee Zee
Answer Source

Declare var test outside, then set it inside someMethod1(). Now you can call someMethod2() on a click event and set test to a.

var test;
someMethod1 = function() {
  test = "testText";

someMethod2 = function() {
  var a = test;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download