Methods and Initializers 28
This commit is contained in:
parent
d9dc02b92f
commit
28b0c71be1
12 changed files with 233 additions and 28 deletions
29
test/methods.lox
Normal file
29
test/methods.lox
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
|
||||
class CoffeeMaker{
|
||||
init(coffee){
|
||||
this.coffee = coffee;
|
||||
}
|
||||
|
||||
brew(){
|
||||
print "Enjoy your cup of " + this.coffee;
|
||||
|
||||
// No reusing the grounds!
|
||||
this.coffee = nil;
|
||||
}
|
||||
}
|
||||
|
||||
var maker = CoffeeMaker("coffee and chicory");
|
||||
maker.brew();
|
||||
|
||||
class Oops{
|
||||
init(){
|
||||
fun f(){
|
||||
print "not a method";
|
||||
}
|
||||
this.field = f;
|
||||
}
|
||||
}
|
||||
|
||||
var oops = Oops();
|
||||
oops.field();
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue