Last active
August 29, 2015 13:56
-
-
Save peterpme/9330438 to your computer and use it in GitHub Desktop.
Javascript: Function Decorator
This file contains hidden or 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
// Function Decorator: | |
// Takes one function as an argument, returns another function. The returned function is a variation of the argument function. | |
function not (fn) { | |
return function (argument) { | |
return !fn(argument); | |
}; | |
} | |
function something(x){ | |
return x !== null; | |
} | |
var nothing = not(something); | |
console.log(something(5)); | |
// true | |
console.log(nothing(5)); | |
// false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment