Methods and Initializers 28

This commit is contained in:
nazrin 2025-06-14 14:50:40 +00:00
parent d9dc02b92f
commit 28b0c71be1
12 changed files with 233 additions and 28 deletions

29
test/methods.lox Normal file
View 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();