doc: create what happen to this section
This commit is contained in:
1 parent
3e7607ae34
commit
8457e8a775
1 file changed
+30
@@ -49,3 +49,33 @@ function namedFunction() {
|
|||||||
console.log("this === " + this); // this === #btn1
|
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( /*....*/ );
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
```
|
||||||
Reference in new issue
Block a user