Skip to content

Instantly share code, notes, and snippets.

@xelaz
Created October 21, 2015 14:54
Show Gist options
  • Save xelaz/9198b8a4b98238108a7a to your computer and use it in GitHub Desktop.
Save xelaz/9198b8a4b98238108a7a to your computer and use it in GitHub Desktop.
Debug Function call on objects
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