Skip to content

Instantly share code, notes, and snippets.

@krisselden
Created July 3, 2012 06:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krisselden/3038022 to your computer and use it in GitHub Desktop.
Save krisselden/3038022 to your computer and use it in GitHub Desktop.
Provides anonymous functions display names in Safari and Firefox
(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