-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex6.js
More file actions
70 lines (54 loc) · 1.52 KB
/
Copy pathindex6.js
File metadata and controls
70 lines (54 loc) · 1.52 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// class 的基本操作
// class Card {
// constructor(name) {
// this.name = name;
// }
// }
// const card1 = new Card("顏嘉緯");
// console.log(card1);
// console.log(card1.name);
// ----------------------------------------------------------------
// this
// class Card {
// constructor(name) {
// this.name = name;
// // this.hellooo = this.hello.bind(this) //綁定在constructor
// }
// hello = () => {
// console.log('hello', this.name); // hello被存在prototype的寫法, 一百個物件只有過hello, 節省記憶體空間
// }
// }
// // Card.prototype.helloo = function() {}
// const card1 = new Card("顏嘉緯");
// //console.log('card1', card1);
// card1.hello()
// const a = { name: 'John'}
// a.helloo = card1.hello
// a.helloo()
//大部分情況都會根據物件本身的屬性去做運算, 但有時候會需要根據外部的變數去做運算, 這時候就需要用到bind
// ----------------------------------------------------------------
//繼承
class Car {
constructor(initName) {
this.name = initName
}
start() {
console.log('車子開始啟動');
}
}
class Porshe extends Car {
constructor(namePorshe) {
super(namePorshe)
}
start2() {
super.start()
console.log('車子排氣');
}
start() { // 蓋過父類別的start
super.start()
console.log('porshe開始啟動');
}
}
const p1 = new Porshe("顏嘉緯的保時捷")
p1.start()
console.log('name', p1.name);