The structure of an API class
First, let's define a few terms. According to Mozilla's object-oriented JavaScript documentation, a class is sort of like a template for an object. It pre-defines the methods and properties of an object generated from the class.
An object therefore, is simply an instance of a class!
A method is a function or subroutine that's declared as part of a class (and any objects that are instances of that class).
A constructor is a special type of function that runs when an object is declared as a new instance of a class using the new
keyword. In ServiceNow, this constructor function is usually called initialize
. Any arguments passed into the class during instantiation will be passed into this function, which effectively builds the object that will be returned.
Note
Naming convention dictates that while variable names use camelCase
capitalization, class names use SentenceCase
capitalization.
Here is a simple example of what a very simple class might look like:
var MyClass ...