Last active
May 1, 2024 21:13
-
-
Save dgeibi/6a81b55d02cbe94456a17fa44747de0d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 listProperties(obj, objStr, option){ | |
| var getPropertyNames = function(obj){ | |
| var keys = []; | |
| for(var key in obj){ | |
| keys.push(key); | |
| } | |
| return keys; | |
| }; | |
| var func = getPropertyNames; | |
| if(option === 1) { | |
| func = Object.getOwnPropertyNames; | |
| } else if (option === 2) { | |
| func = Object.keys; | |
| } | |
| var callback = function(element) { | |
| var type; | |
| try { | |
| type = typeof obj[element]; | |
| } catch(err) { | |
| } | |
| if( type !== 'function') { | |
| return objStr + '.' + element ; | |
| } else { | |
| return objStr + '.' + element + '()' ; | |
| } | |
| }; | |
| //console.log('/* userAgent: ' + navigator.userAgent + ' */'); | |
| //console.log(func(obj).map(callback).join('\n')); | |
| document.write('/* userAgent: ' + navigator.userAgent + ' */<br>'); | |
| var out = func(obj).map(callback); | |
| for(var i = 0; i< out.length; i+=1) { | |
| document.write(out[i] + '<br>'); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment