Skip to content

Instantly share code, notes, and snippets.

@JamieMason
Created June 16, 2011 09:10
Show Gist options
  • Save JamieMason/1028925 to your computer and use it in GitHub Desktop.
Save JamieMason/1028925 to your computer and use it in GitHub Desktop.
A Bookmarklet/Favelet to log to the console every member of an Object and it's prototype chain, flattened and sorted into alphabetical order.
javascript:(function(oSubject){var%20key,arr%20=%20[],obj%20=%20{},i;for%20(key%20in%20oSubject){arr.push([key,%20oSubject[key]]);}arr.sort();for%20(i%20=%200;%20i%20<%20arr.length;%20i++){obj[arr[i][0]]%20=%20arr[i][1];}console.log(obj);}%20(eval(prompt(%27Enter%20reference%20to%20Object%27))));void(0);
(function(oSubject)
{
var key,
arr = [],
obj = {},
i;
// copy key name and type to an array
for (key in oSubject)
{
arr.push([key, oSubject[key]]);
}
// sort it a-z
arr.sort();
// copy to an object, just because I prefer the presentation
for (i = 0; i < arr.length; i++)
{
obj[arr[i][0]] = arr[i][1];
}
// log the API
console.log(obj);
} (
eval(prompt('Enter reference to Object')))
);
@JamieMason
Copy link
Author

A Bookmarklet/Favelet to log to the console every member of an Object and it's prototype chain, flattened and sorted into alphabetical order.

I find this is a quicker way to see what's available than having to click to expand proto for every Object in the chain - where the a-z order then restarts for each one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment