diff --git a/source/_posts/this关键字.md b/source/_posts/this关键字.md index e01feac..0c523d2 100644 --- a/source/_posts/this关键字.md +++ b/source/_posts/this关键字.md @@ -48,4 +48,34 @@ function init() { function namedFunction() { console.log("this === " + this); // this === #btn1 } +``` + +### 更多JavaScript:this关关键字会发生什么 +```javascript +let defaultReply = "Hello World"; +button.addEventListener("click", function() { + draftReply(defaultReply); +}); +``` +```javascript +function draftReply(startingText) { + this.parentNode.appendNode( /*....*/); + // ... +} +// this === button +``` + +vs + +```javascript +let defaultReply = "Hello World"; +button.addEventListener("click", () => { + draftReply(defaultReply); +}); +``` +```javascript +function draftReply(startingText) { + this.parentNode.appendNode( /*....*/ ); + // ... +} ``` \ No newline at end of file