Skip to content

Instantly share code, notes, and snippets.

@SohumB
Last active August 29, 2015 13:55
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 SohumB/8699077 to your computer and use it in GitHub Desktop.
Save SohumB/8699077 to your computer and use it in GitHub Desktop.
var fs = require('fs');
// then
hug(null, fs.writeFileSync, 'filename', 'data')
// should return the following function:
function() {
fs.writeFileSync('filename', 'data');
}
// except we need to "preserve" context
// so if the first argument is null, then we're actually returning:
function() {
var fn = fs.writeFileSync.bind(null);
fn('filename', 'data');
}
// ideally we'd want a version that doesn't need the scope argument at all
// but I'm pretty sure that's impossible in javascript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment