Created
May 5, 2016 15:51
-
-
Save chestozo/478e1b7f901fd8b96fbf39fc4a7bb114 to your computer and use it in GitHub Desktop.
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
function wrap(obj, onlyOwnProperties) { | |
obj = obj || {}; | |
for (var propName in obj) { | |
if (onlyOwnProperties && obj.hasOwnProperty(propName)) { | |
continue; | |
} | |
if (typeof obj[propName] !== 'function') { | |
continue; | |
} | |
wrapMethod(obj, propName); | |
} | |
} | |
function wrapMethod(obj, methodName) { | |
var _method = obj[methodName]; | |
var counter = 0; | |
obj[methodName] = function() { | |
var result = _method.apply(obj, arguments); | |
var index = ++counter; | |
console.log(index, methodName, arguments, '>>>', result); | |
return result; | |
}; | |
for (var prop in _method) { | |
if (_method.hasOwnProperty(prop)) { | |
obj[methodName][prop] = _method[prop]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment