Last active
April 22, 2024 09:15
-
-
Save xinglongjizi/fe96b85117cd751e2466706002c37914 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var a = function() { | |
| console.log(this); | |
| }; | |
| a() // ===> window | |
| a.call({}) // ===> {} | |
| var b = a.bind({b: 'b'}) | |
| b() // ===> {b: 'b'} | |
| var c = b.bind({'c': 'c'}) | |
| c() // 并不会打印{c: 'c'},打印{b: 'b'} | |
| b.call({'bb': 'bb'}) // 并不会打印{bb: 'bb'},打印{b: 'b'} | |
| /* | |
| 结论:一个函数被bind过了,后面再次的bind会忽略第一次this参数,而是一直用第一次bind的值 | |
| 祥见MDN https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Function/bind | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment