<script>
var methodize = function (func, attr) {
return function () {
return func.apply(this, [(attr ? this[attr] : this)].concat([].slice.call(arguments)));
};
};
var demethodize = function (fn) {
return function () {
var args = [].slice.call(arguments, 1);
return fn.apply(arguments[0], args)
}
};
function add(i, j) { return i + j; }
Number.prototype.add = methodize(add);
console.log((3).add(4))
console.log(demethodize(Number.prototype.add)(5, 6))
</script>
网友评论