Skip to content

Instantly share code, notes, and snippets.

@prabirshrestha
Last active December 17, 2015 01:39
Show Gist options
  • Save prabirshrestha/5530404 to your computer and use it in GitHub Desktop.
Save prabirshrestha/5530404 to your computer and use it in GitHub Desktop.
myStuff.forEach(function stuff){
var subStuff = stuff.subStuff;
doSomething({
success: (function(subStuff) { // creates a function scope
return function(results) { // the actual success callback with subStuff scoped
// subStuff and results are now function scoped
};
})(subStuff); // immediately invoke the function.
});
});
@prabirshrestha
Copy link
Author

myStuff.forEach(function stuff){

    var subStuff = stuff.subStuff;

    doSomething({

        success: (function(subStuffScoped) { // creates a function scope
            return function(results) { // the actual success callback with subStuff scoped
                // subStuffScoped and results are now function scoped
            };
        })(subStuff); // immediately invoke the function.

    });

});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment