Functionally Equivalent Language Translation →
(class Foo (mvar# a) (defun ctor (anA) (= (-> this :a) anA)))
The THIS
instruction is a pseudo-receiver that allows you to call class methods within the class that you are creating. Note that the target membervariable must be expressed as a keyword or it will be interpreted as a variable name in the rendered code. See also MY which offers a shorter and neater way of doing this.
Let's take the exmple code in the header and see how that looks as PHP:
class Foo { protected $a; function __construct($anA) { $this->a = $anA; } }
We can see that the special name ctor
has been translated into the PHP equivalent of the constructor function name for clases. Please see CLASS for further details on this and other special names that are recognised.
The same example translated into JavaScript gives us this:
function Foo (anA) { this.a = anA; }
Here we can see that this time the ctor
function signature has been used in the classname function signature and the body of it forms the "constructor" of the "class".