Created
July 3, 2012 06:16
-
-
Save krisselden/3038022 to your computer and use it in GitHub Desktop.
Provides anonymous functions display names in Safari and Firefox
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 () { | |
function createDisplayNames(obj, path) { | |
var val, key; | |
if (typeof obj === 'string') { | |
path = obj; | |
obj = Ember.getPath(path); | |
} | |
for (key in obj) { | |
// skip contructor | |
if (key === 'contructor') continue; | |
if (obj.hasOwnProperty(key)) { | |
val = obj[key]; | |
if (typeof val === 'function') { | |
// skip if already assigned | |
if (val.displayName) continue; | |
// skip if obj is Function and method copied from superclass | |
if (typeof obj === 'function') { | |
if (key === 'superclass') continue; | |
if (obj.superclass && obj.superclass[key] === val) continue; | |
} | |
val.displayName = path + '.' + key; | |
} | |
} | |
} | |
} | |
function createNamespaceDisplayNames(namespace) { | |
var val, key, obj = window[namespace]; | |
for (key in obj) { | |
val = obj[key]; | |
if (typeof val === 'function') { | |
val.displayName = namespace + '.' + key; | |
createDisplayNames(val, namespace + '.' + key); | |
// initialize prototype if is Ember Class | |
if (val.isClass) val.proto(); | |
createDisplayNames(val.prototype, namespace + '.' + key + '.prototype'); | |
} | |
} | |
} | |
createDisplayNames('jQuery'); | |
createDisplayNames('jQuery.fn'); | |
createNamespaceDisplayNames('Ember'); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment