doc: create a comparision section
This commit is contained in:
1 parent
043e2255d6
commit
8f43853f81
1 file changed
+18
@@ -96,4 +96,22 @@ skittle.addEventListener("dblclick", () => {
|
||||
this.parentNode.removeChild(this);
|
||||
id("result").textContent = ":O You ate a skittle...";
|
||||
});
|
||||
```
|
||||
|
||||
### 用this比较不同的回调函数
|
||||
```javascript
|
||||
function init() {
|
||||
// this === 窗口
|
||||
id("btn1").addEventListener("click", namedFunction)l
|
||||
id("btn2").addEventListener("click", function() {
|
||||
console.log("this === " + this); // this === #btn2
|
||||
});
|
||||
id("btn3").addEventListener("click", () => {
|
||||
console.log("this === " + this); // this === 窗口
|
||||
});
|
||||
}
|
||||
|
||||
function namedFunction() {
|
||||
console.log("this === " + this); // this === #btn1
|
||||
}
|
||||
```
|
||||
Reference in new issue
Block a user