The usual names for these “Object oriented” concepts are objects (editor,
in these examples, is a reference to an instance of the OutlineEditor
object), the properties (named sub-values, if you like) which are defined for these objects (editor.selection
etc), and any methods (verbs or functions, if you like) which are defined for these objects (e.g. OutlineEditor.setCollapsed
)
AppleScript uses the same structures but different notations.
where JS lets us write:
-
editor.setCollapsed(items)
, or
editor["setCollapsed"](items)
incantations for an equivalent interface in AppleScript can be written in a variety of synonymous forms.
tell editor
setCollapsed(items)
end tell
or
tell editor to setCollapsed(items)
or
editors's setCollapsed(items)
or
setCollapsed(items) of editor
One way of thinking about what is going on under the hood is that you have what AppleScript calls a record, and Python, JS etc would call a dictionary or object, which is a set of key:value
pairs.
The keys are typically strings – we often think of them as names.
-
The values can be anything – simple numbers or strings, other records/objects, even functions. (Thus what we call methods)
-
and the particular value which an object gives you get when you ask for it by key doesn’t have to be fixed and static, it can be a property calculated, at run-time, using logic inside the object. Function values (methods) in the object may be able to make use of other values in the object (some hidden, some visible and publicly named in the object’s key-list), when calculating a result at run-time
Think of the various properties and methods of of JS Arrays and AppleScript lists, for example, starting with xs.length
⇄ length of xs
The value you get from the Array Object for a “length” key is only calculated at run-time.
(() => {
"use strict";
const xs = ["Alpha", "Beta", "Gamma"];
return xs["length"]; // Shorthand: xs.length
})();
In AppleScript you can write any of the following:
set xs to {"Alpha", "Beta", "Gamma"}
tell xs
length
end tell
length of xs
tell xs to length
xs's length
The last of those is closest to JS. The AS 's
is a synonym of the JS dot.