Skip to content

Instantly share code, notes, and snippets.

@cowboy
Created January 28, 2015 21:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cowboy/76e917b3b019b2dbabeb to your computer and use it in GitHub Desktop.
Save cowboy/76e917b3b019b2dbabeb to your computer and use it in GitHub Desktop.
JavaScript: Why use an explicit variable when you can just bind and use this instead?
// Why use an explicit variable...
function lame() {
var args = arguments;
return function(fn) {
console.group.apply(console, args);
fn();
console.groupEnd();
};
}
lame('test group')
(function() {
console.log('this is a test');
});
// ...when you can just bind and use this instead?
function awesome() {
return function(fn) {
console.group.apply(console, this);
fn();
console.groupEnd();
}.bind(arguments);
}
awesome('another group')
(function() {
console.log('this is another test');
});
@cowboy
Copy link
Author

cowboy commented Jan 29, 2015

should I be surprised that my joke didn't get a single lol

@bstst
Copy link

bstst commented Feb 10, 2015

lol

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