Send variable name and value to console
by Andreas Renberg
JavaScript
function Mouse(x, y) {
this.x = x;
this.y = y;
}
function Keyboard(key) {
this.a = (key == 97);
this.b = (key == 98);
this.c = (key == 99);
this.d = (key == 100);
this.e = (key == 101);
}
var m1 = new Mouse(100, 200);
var kbd = new Keyboard(100);
var something = {x:350, y:400};
show(m1, 'x');
show(kbd, 'c');
show(kbd, 'd');
show(something, 'x');
function show(object, property) {
var className = object.constructor.name;
console.log(className + "#" + property + ":", object[property]);
}