mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-18 13:49:59 +01:00
Use "construct" instead of "this" to define constructors.
This commit is contained in:
@ -172,18 +172,18 @@ constructor, like so:
|
||||
|
||||
:::dart
|
||||
class Unicorn {
|
||||
this new(name, color) {
|
||||
construct new(name, color) {
|
||||
IO.print("My name is " + name + " and I am " + color + ".")
|
||||
}
|
||||
}
|
||||
|
||||
The `this` before the method name makes it a constructor. The `new` isn't
|
||||
The `construct` before the method name makes it a constructor. The `new` isn't
|
||||
special. Constructors can have any name you like, which lets you clarify how it
|
||||
creates the instance:
|
||||
|
||||
:::dart
|
||||
class Unicorn {
|
||||
this brown(name) {
|
||||
construct brown(name) {
|
||||
IO.print("My name is " + name + " and I am brown.")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user