Guest User

Untitled

a guest
Feb 19th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. /**
  2. Returns the name of this class. If the name is not known, triggers
  3. a search. This can be expensive the first time it is called.
  4. */
  5. objectClassName: function() {
  6. if (!this._objectClassName) this._findObjectClassNames() ;
  7. if (this._objectClassName) return this._objectClassName ;
  8. var ret = this ;
  9. while(ret && !ret._objectClassName) ret = ret._type;
  10. return (ret && ret._objectClassName) ? ret._objectClassName : 'Anonymous' ;
  11. },
  12.  
  13. /** @private
  14. This is a way of performing brute-force introspection. This searches
  15. through all the top-level properties looking for classes. When it finds
  16. one, it saves the class path name.
  17. */
  18. _findObjectClassNames: function() {
  19.  
  20. if (SC._foundObjectClassNames) return ;
  21. SC._foundObjectClassNames = true ;
  22.  
  23. var seen = [] ;
  24. var searchObject = function(root, object, levels) {
  25. levels-- ;
  26.  
  27. // not the fastest, but safe
  28. if (seen.indexOf(object) >= 0) return ;
  29. seen.push(object) ;
  30.  
  31. for(var key in object) {
  32. if (key == '__scope__') continue ;
  33. if (key == '_type') continue ;
  34. if (!key.match(/^[A-Z0-9]/)) continue ;
  35.  
  36. var path = (root) ? [root,key].join('.') : key ;
  37. var value = object[key] ;
  38.  
  39.  
  40. switch($type(value)) {
  41. case T_CLASS:
  42. if (!value._objectClassName) value._objectClassName = path;
  43. if (levels>=0) searchObject(path, value, levels) ;
  44. break ;
  45.  
  46. case T_OBJECT:
  47. if (levels>=0) searchObject(path, value, levels) ;
  48. break ;
  49.  
  50. case T_HASH:
  51. if (((root != null) || (path=='SC')) && (levels>=0)) searchObject(path, value, levels) ;
  52. break ;
  53.  
  54. default:
  55. break;
  56. }
  57. }
  58. } ;
  59.  
  60. searchObject(null, window, 2) ;
  61. },
  62.  
  63. toString: function() { return this.objectClassName(); },
Add Comment
Please, Sign In to add comment