Posted By

f on 02/25/11


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

espig
wirenaught


Object Property Information


 / Published in: JavaScript
 

Interface

  • function(object object_name)

Description

Construct a table of property information describing its index in the table, owner, type, identifier and value.

The result is returned from an anonymous function so the global name space won't be corrupted. A user can also provide a string to be the name of a global variable to store the result table.

Bookmarklet

The bookmarklet is generated by Closure Compiler .

  1. /* <bookmarklet> *\
  2. javascript:(function(e){var b,a,f,d,c=[];for(b in e){f=e.hasOwnProperty(b)?"this":"parent";d=typeof a;if(d=="object")d=a==null?"null":a.constructor;a=e[b];c.push([c.length,f,d,b,a]);c.properties.push(b);c.values.push(a)}return c})();
  3. \* </bookmarklet> */
  4. (function(instance)
  5. {
  6. var property, value, owner, type;
  7.  
  8. var table = [];
  9.  
  10. for (property in instance)
  11. {
  12. /* Construct the table of property information. */
  13. owner = instance.hasOwnProperty(property) ? "this" : "parent";
  14. type = typeof value;
  15. if (type == "object")
  16. type = value == null ? "null" : value.constructor;
  17. value = instance[property];
  18. table.push([table.length, owner, type, property, value]);
  19. /* Store properties. */
  20. table.properties.push(property);
  21. /* Store values. */
  22. table.values.push(value);
  23. }
  24. return table;
  25. })();

Report this snippet  

You need to login to post a comment.