Forked from thisnameissoclever/getMethodsAndProperties.js
Created
May 26, 2020 05:08
-
-
Save pchaozhong/fe657b8dc68e7d8e27ce23696607a118 to your computer and use it in GitHub Desktop.
ServiceNow: Get Methods and Properties of an object
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
| var methodsAndProperties = []; | |
| var testObj = new GlideFilter('a=b', 'rule'); //TODO: replace this with whatever object you want to test | |
| getMethodsAndProperties(methodsAndProperties, testObj); | |
| gs.print('\n' + methodsAndProperties.join('\n')); | |
| /** | |
| * Populates an extant array in-place, of methods and properties of a given object. | |
| * @param methodsAndProperties {array} - the array to populate/modify in-place. | |
| * @param testObj {object} - The object to get the list of properties for. | |
| */ | |
| function getMethodsAndProperties(methodsAndProperties, testObj) { | |
| var prop; | |
| for (prop in testObj) { | |
| try { | |
| if (typeof testObj[prop] === 'object') { | |
| methodsAndProperties.push(prop + ' {}'); | |
| } else if (typeof testObj[prop] === 'function') { | |
| methodsAndProperties.push(prop + '()'); | |
| } else { | |
| methodsAndProperties.push(prop); | |
| } | |
| } catch(e) {} | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment