Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var funcArr = [];
- for(var year = 0; year < 5; year++) {
- var someFunc = (function (yr) {
- return function(grid) {
- // console log any additional params being passed in
- console.log('grid', grid);
- // console log year parameter being passed in by the .bind method
- console.log('year', yr);
- }
- // bind this and pass in the year variable
- }.bind(this, year))();
- funcArr.push(someFunc);
- }
- funcArr.forEach(function(fn) {
- // call each function that has a reference to the correct value of the
- // year iterator and give each function additional parameters('grid')
- fn('grid param');
- });
Add Comment
Please, Sign In to add comment