Skip to content
justinmann edited this page Dec 24, 2017 · 3 revisions

Class == function

There is no distinction between a class and a function they are the same thing.

Here is what a class definition looks like

class(
	x := 0
	method1() { x += 1 }
	method2() { x += 2 }
) { this }

The { this } means that the function class is returning the object used to store all of the variables and inner functions from this function.

Because a class is a function, creating a class is the same as calling a function

c : class(x : 1)

Class with a constructor

class(
	x : 2
	method1() { }
) {
	if (x == 0) {
		throw "x cannot be zero"
	}
	this
}

c : class(x : 0)

Clone this wiki locally