javascript - What is context in _.each(list, iterator, [context])? -


i new underscore.js. purpose of [context] in _.each()? how should used?

the context parameter sets value of this in iterator function.

var someotherarray = ["name","patrick","d","w"];  _.each([1, 2, 3], function(num) {      // in here, "this" refers same array "someotherarray"      alert( this[num] ); // num value array being iterated                         //    this[num] gets item @ "num" index of                         //    someotherarray. }, someotherarray); 

working example: http://jsfiddle.net/a6rx4/

it uses number each member of array being iterated item @ index of someotherarray, represented this since passed context parameter.

if not set context, this refer window object.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -