Created
September 25, 2012 08:23
-
-
Save manix84/3780621 to your computer and use it in GitHub Desktop.
Adding display name to object tree.
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
var someClassNameHere = { | |
someVariable: '', | |
someFunction: function () { // prototype.displayName = "someClassNameHere.someFunction" | |
console.debug('some message'); // console.debug > "[someClassNameHere.someFunction] some message" | |
}, | |
someObject: { | |
someFunction: function () { // prototype.displayName = "someClassNameHere.someObject.someFunction" | |
console.warn('some message'); // console.warn > "[someClassNameHere.someObject.someFunction] some message" | |
}, | |
someVariable: 0 | |
} | |
}; | |
var console = { | |
debug: function () { | |
var displayName = '[' + arguments.callee.caller.prototype.displayName + ']'; | |
Array.prototype.reverse.call(arguments); | |
Array.prototype.push.call(arguments, displayName); | |
Array.prototype.reverse.call(arguments); | |
if (!!window.console.debug) { | |
window.console.debug.apply(window.console, arguments); | |
} | |
}, | |
info: function () { | |
var displayName = '[' + arguments.callee.caller.prototype.displayName + ']'; | |
Array.prototype.reverse.call(arguments); | |
Array.prototype.push.call(arguments, displayName); | |
Array.prototype.reverse.call(arguments); | |
if (!!window.console.info) { | |
window.console.info.apply(window.console, arguments); | |
} | |
}, | |
warn: function () { | |
var displayName = '[' + arguments.callee.caller.prototype.displayName + ']'; | |
Array.prototype.reverse.call(arguments); | |
Array.prototype.push.call(arguments, displayName); | |
Array.prototype.reverse.call(arguments); | |
if (!!window.console.warn) { | |
window.console.warn.apply(window.console, arguments); | |
} | |
} | |
}, | |
addDisplayNames = function (classObj, baseName) { | |
var objName; | |
for (objName in classObj) { | |
if (classObj.hasOwnProperty(objName) && !!classObj[objName]) { | |
if (typeof classObj[objName] === 'function') { | |
classObj[objName].prototype = { | |
displayName: baseName + '.' + objName | |
}; | |
} | |
if (typeof classObj[objName] === 'object' && objName !== 'prototype') { | |
addDisplayNames(classObj[objName], baseName + '.' + objName); | |
} | |
} | |
} | |
}; | |
addDisplayNames(someClassNameHere, 'someClassNameHere'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment