We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f3959a0 commit a0e1c8dCopy full SHA for a0e1c8d
docs/function.md
@@ -655,6 +655,26 @@ mult2(plus1(5))
655
656
```
657
658
+## 函数绑定
659
+
660
+箭头函数可以绑定this对象,大大减少了显式绑定this对象的写法(call、apply、bind)。但是,箭头函数并不适用于所有场合,所以ES7提出了“函数绑定”(function bind)运算符,用来取代call、apply、bind调用。虽然该语法还是ES7的一个提案,但是Babel转码器已经支持。
661
662
+函数绑定运算符是并排的两个双引号(::),双引号左边是一个对象,右边是一个函数。该运算符会自动将左边的对象,作为上下文环境(即this对象),绑定到右边的函数上面。
663
664
+```javascript
665
+let log = ::console.log;
666
+// 等同于
667
+var log = console.log.bind(console);
668
669
+foo::bar;
670
671
+bar.call(foo);
672
673
+foo::bar(...arguments);
674
675
+bar.apply(foo, arguments);
676
+```
677
678
## 尾调用优化
679
680
### 什么是尾调用?
0 commit comments