Guest User

Untitled

a guest
Nov 18th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. var funcArr = [];
  2.  
  3. for(var year = 0; year < 5; year++) {
  4.  
  5. var someFunc = (function (yr) {
  6. return function(grid) {
  7.  
  8. // console log any additional params being passed in
  9. console.log('grid', grid);
  10.  
  11. // console log year parameter being passed in by the .bind method
  12. console.log('year', yr);
  13. }
  14.  
  15. // bind this and pass in the year variable
  16. }.bind(this, year))();
  17.  
  18. funcArr.push(someFunc);
  19. }
  20.  
  21.  
  22. funcArr.forEach(function(fn) {
  23. // call each function that has a reference to the correct value of the
  24. // year iterator and give each function additional parameters('grid')
  25. fn('grid param');
  26. });
Add Comment
Please, Sign In to add comment