Object and Class Types
Object types are basically just containers containing assignments of variables and functions
You can access the members of the object using the .
accessor
To create an object constructor (like many languages have classes that you can instantiate) we create a function that returns an object
You can also store functions inside of objects, allowing objects to completely cover regular object behaviors from other languages
There will not be any sort of this
or self
parameter as in other languages to access an objects members from within itself/any contained functions. Instead because the functions are at the same scope as the declaration of the objects members, those members are available to the function.
If we remove any unnecessary syntax, the shorthand for constructing an object looks like this:
that is, just a function that returns an object literal, no need for braces or return
.
Dunder Methods
Similar to python, objects can define custom so-called "double-underscore" or "dunder" methods, which hook into the language's built-in functionality.
Though actually for __add__
, it might make more sense for it to be global, and you add an alternate that gets dispatched on rather than including it in the object itself:
(TODO: longer explanation)