implementing methods and initializers (ch28)

This commit is contained in:
2024-08-31 10:24:48 +02:00
parent c8cd24afbf
commit 3c1c37799c
9 changed files with 123 additions and 2 deletions
+9
View File
@@ -0,0 +1,9 @@
class Scone {
topping(first, second) {
return "scone with " + first + " and " + second;
}
}
var scone = Scone();
var result = scone.topping("berries", "cream");
print result;
+8
View File
@@ -0,0 +1,8 @@
class Brunch {
bacon() {}
eggs() {}
}
var brunch = Brunch();
print brunch;
brunch.bacon();
+11
View File
@@ -0,0 +1,11 @@
class Person {
sayName() {
print this.name;
}
}
var jane = Person();
jane.name = "Jane";
var method = jane.sayName;
method();