2017-05-24 110 views
0

最近,當我用Rxjs 5,我下載Rxjs使用NPM安裝[email protected],從下node_modules下載的代碼,我發現Observable.d.ts在Rxjs文件夾中,我看到了它的聲明構造象下面這樣:此關鍵字的功能參數

* 
* @constructor 
* @param {Function} subscribe the function that is called when the Observable is 
* initially subscribed to. This function is given a Subscriber, to which new values 
* can be `next`ed, or an `error` method can be called to raise an error, or 
* `complete` can be called to notify of a successful completion. 
*/ 
constructor(subscribe?: <R>(this: Observable<T>, subscriber: Subscriber<R>) => TeardownLogic); 

我的問題是:這是什麼關鍵字的訂閱?:函數類型聲明的使用(這一點:觀察的,...),是否有打字原稿這個關鍵字的使用像一些文檔這裏?謝謝。

回答

1

你可以(因爲打字稿的2.0版本)規定什麼是this被調用的函數,當你期待。

Specifying the type of this for functions描述:

上指定的這類或類型的 接口跟進,函數和方法現在可以聲明的這一點,他們 期望的類型。

默認情況下,這個函數裏面的類型是任何。從 開始TypeScript 2.0,你可以提供一個明確的這個參數。這 參數是放在第一位的功能

注意,這將不會翻譯成JS的參數列表 假的參數,所以它不是功能的真正理由。

+0

謝謝你,幫我找到文檔。 – IcyBrk