Created
January 28, 2015 21:10
-
-
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?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
should I be surprised that my joke didn't get a single lol