forked from MarkTechson/tau-intro-to-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path05-05-02-objects.js
41 lines (34 loc) · 941 Bytes
/
05-05-02-objects.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
setTimeout(() => {
console.log("please wait")
}, 4000);
const vegitables_and_fruits = {
name: "potato",
isTasty: true,
//"åß®√嬩": false,
eatVegitable: function () {
console.log("I'm eating " + this.name);
}
};
//vegitables_and_fruits.name = "tomato";
//vegitables_and_fruits.isTasty = false;
//console.log(vegitables_and_fruits["åß®√嬩"]);
//console.log(vegitables_and_fruits);
vegitables_and_fruits.eatVegitable();
class Food {
constructor(name, isTasty) {
this.name = name;
this.isTasty = isTasty;
}
eatVegitable() {
console.log("we are fond of " + this.name);
}
}
const myFood = new Food("cucumber", true);
myFood.eatVegitable();
console.log(myFood);
const ourFood = new Food("banana", false);
ourFood.eatVegitable();
console.log(ourFood);
const theirFood = new Food("pineapple", "sure");
theirFood.eatVegitable();
console.log (theirFood);