Created
October 21, 2015 14:54
-
-
Save xelaz/9198b8a4b98238108a7a to your computer and use it in GitHub Desktop.
Debug Function call on objects
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
var Person = function(location) { | |
this.location = location; | |
}; | |
Person.prototype.goto = function() { | |
console.log('goto: ', this.location); | |
}; | |
prodebug(Person); | |
function prodebug(obj) { | |
var pro = obj.prototype, old; | |
for(var i in pro) { | |
if(typeof pro[i] === 'function') { | |
pro[i] = proxy(pro[i], i); | |
} | |
} | |
function proxy(func, name) { | |
return function debug() { | |
console.log('Function: ', name); | |
console.log('+- args: ', arguments); | |
return func.apply(this, arguments); | |
} | |
} | |
} | |
var alex = new Person('London'); | |
alex.goto(); | |
var max = new Person('Berlin'); | |
max.goto(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment