Created
July 8, 2015 18:37
-
-
Save lamchau/47bc78cafef6218a7b6c to your computer and use it in GitHub Desktop.
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 demethodize(fn) { | |
if (typeof fn === "function") { | |
return Function.bind.bind(Function.call)(fn); | |
} | |
return null; | |
} | |
_.mixin((function() { | |
return { | |
demethodize: function(fn) { | |
return _.bind(_.call, fn); | |
} | |
}; | |
})()); | |
function testDemethodize(input, fn) { | |
var result = Array.isArray(input) ? input.map(fn) : fn.call(null, null, input); | |
console.log('result', result); | |
} | |
testDemethodize(['a', 'b', 'c'], _.demethodize(String.prototype.toUpperCase)); | |
testDemethodize(['a', 'b', 'c'], demethodize(String.prototype.toUpperCase)); | |
testDemethodize({ a: 1 }, _.demethodize(Object.keys)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment