0

Let's have a look at this short JavaScript snippet:

function _function(param1, param2) {
  console.log(param1 + " and " + param2);
}

function test(callback) {
  var i = 0;
  var j = undefined;
  var test = setTimeout(callback.bind(null, i, j), 1000);
  i = 1;
  j = 2;
}

test(_function);

Now it works as expected: console.log is going to display

0 and undefined

Is it possible to only update j (here: to 2) while keeping i equal to 0 within _functions's scope and without using j as a global variable ?

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
user1511417
  • 1,880
  • 3
  • 20
  • 41

0 Answers0