Created
June 16, 2011 09:10
-
-
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.
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
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); |
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(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'))) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.