Last active
December 29, 2015 19:59
-
-
Save A/7720516 to your computer and use it in GitHub Desktop.
JS Functions wrappers.
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
/** | |
* Abstract | |
*/ | |
var obj = { | |
wrapped: function(a,b) { | |
console.log('this:', this); | |
console.log('a:', a); | |
console.log('b:', b); | |
} | |
} | |
var wrapper = function () { | |
obj.wrapped.apply(obj, arguments); | |
} | |
obj.wrapped(1,2); | |
wrapper(3,4); | |
/** | |
* Wrapper for express res.send() method. | |
*/ | |
module.export = { | |
send: function () { | |
return function (req,res) { | |
res.send.apply(res, arguments); | |
}; | |
} | |
}; | |
/** | |
* Wrapper for Array.push() method; | |
*/ | |
var arr = new Array(); | |
arr.push = function() { | |
console.log('push'); | |
return arr.__proto__.push.apply(arr, arguments); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment