This really clicked for me in Javascript when revisiting the saying "functions are first-class objects in JS".
I think most people know this in the context of callbacks or lambdas, but it's useful to keep in mind that this is how all functions in JS work: A function is an object with support for a special "call" operation and () is an operator that invokes that operation on whatever object is given.
So Application('System Events').processes() is invoking "call" on the object contained in the "processes" property.
But because it's an object, it also supports all the other operations of objects, such as attaching properties - which can contain other callable objects.
So Application('System Events').processes.name() is fetching the "name" property of the same object and invoking "call" on that value.
Comments
This really clicked for me in Javascript when revisiting the saying "functions are first-class objects in JS".
I think most people know this in the context of callbacks or lambdas, but it's useful to keep in mind that this is how all functions in JS work: A function is an object with support for a special "call" operation and () is an operator that invokes that operation on whatever object is given.
So Application('System Events').processes() is invoking "call" on the object contained in the "processes" property.
But because it's an object, it also supports all the other operations of objects, such as attaching properties - which can contain other callable objects.
So Application('System Events').processes.name() is fetching the "name" property of the same object and invoking "call" on that value.