Skip to content

Instantly share code, notes, and snippets.

@coolaj86
Created February 16, 2012 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coolaj86/1847455 to your computer and use it in GitHub Desktop.
Save coolaj86/1847455 to your computer and use it in GitHub Desktop.
More issues with closures
// Google "mdn foreach"
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/forEach
function createLogger(i) {
console.log(item + ' ' + list[index]);
}
for (i = 0; i < list.length; i += 1) {
item = 'item' + list[i];
results.push(createLogger(i));
}
results.forEach(function (fn) {
fn();
});
(function(){ return this; }());
// http://stackoverflow.com/questions/3277182/how-to-get-the-global-object-in-javascript
(function () {
"use strict";
var globalish = (function(){ return this; }());
var global = new Function("return this;")();
console.log('g', global);
console.log('ish', !!globalish);
}());
Yes it is!
function bodily() {console.log("This is a bodily function");}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment