class Foo(x, y) {
x: number = x
y: number = y
// optional initializer
init(self) {
// self.x and self.y will be guaranteed to be initialized by this point
// do something self.x or self.y
}
}
This syntax is similar to public class fields but gets rid of the explicit constructor() and replaces it with the ability for the class to have a param list itself.
This syntax is similar to public class fields but gets rid of the explicit
constructor()
and replaces it with the ability for the class to have a param list itself.References: