Skip to content

Instantly share code, notes, and snippets.

@dherman
Created July 28, 2012 18:08
Show Gist options
  • Save dherman/3194222 to your computer and use it in GitHub Desktop.
Save dherman/3194222 to your computer and use it in GitHub Desktop.
Convert methods to unselfish functions
Function.prototype.unselfish = (function(Fp, Ap) {
var applyMethod = Fp.apply,
callMethod = Fp.call;
var apply = callMethod.bind(applyMethod),
call = callMethod.bind(callMethod);
var sliceMethod = Ap.slice;
return function unselfish() {
var f = this;
return function(self) {
return apply(f, self, call(sliceMethod, arguments, 1));
};
};
})(Function.prototype, Array.prototype);
var hasOwn = Object.prototype.hasOwnProperty.unselfish();
console.log(hasOwn({}, "toString")); // false
console.log(hasOwn({foo:1}, "foo")); // true
@medikoo
Copy link

medikoo commented Jul 29, 2012

I get it, thanks for clarification, good tip.

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