Anonymous classes

The name can be left out when declaring a class. The __name attribute will be nil, unless the class expression is in an assignment. The name on the left hand side of the assignment is used instead of nil.

MoonScript:

BigBucket = class extends Bucket
  add_drop: => @drops += 10

assert Bucket.__name == "BigBucket"

You can even leave off the body, meaning you can write a blank anonymous class like this:

MoonScript:

x = class

results matching ""

    No results matching ""