Last active
November 22, 2023 09:48
-
-
Save thisnameissoclever/34332e65d40a01aae2b2799f3793b3ce to your computer and use it in GitHub Desktop.
ServiceNow: Get Methods and Properties of an object
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
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