Open futianshen opened 5 years ago
一旦你瞭解物件你就可以瞭解 JavaScript,JavaScript 中幾乎所有事物都是一種「物件」,或具有類似物件的行為。[a]
this
指向調用this
的物件 [b]所有函式都由一個「物件」呼叫,換句話說所有函式都是物件中的一個「方法」(method) [c]
[1-1] handleClick
由 windows 物件(Global Object)呼叫, this
指向 windows 物件,但由於 babel 預設開啟 Strict Mode 所以變成 undefined
[1-2] 我們希望呼叫 handleClick
這個 method 的時候,this 的指向是 App 這個 Component 的Instance,但我們自訂的method handleClick()
指向的是 Global Object
所以我們我們利用 this.handleClick = this.handleClick.bind(this)
[a]《JavaScript深入精要》p.1 [b]《從 ES6 開始的 JavaScript 學習生活》 this - this [c]《從 ES6 開始的 JavaScript 學習生活》 this - 深入 函式 中
功能:新增、刪除清單內容 網址連結:待補
index.js
Todo.js