Lodash _.after()方法與Lodash _.before()方法相反。此方法用於創建一個函數,該函數在被調用n次或多次後將調用func。
用法:
_.after(n, func)
參數:該方法接受上述和以下所述的兩個參數:
- n:此參數保留數字n,該數字定義在調用func之前的調用次數。
- func:此參數保存將要調用的函數。
返回值:此方法返回新的受限函數。
下麵的示例說明JavaScript中的Lodash _.after()方法。
範例1:在此示例中,我們嘗試調用該函數3次,但僅將其調用3次。
// Requiring the lodash library
const _ = require("lodash");
// Applying _.after() method
var gfg = _.after(3, function () {
console.log('Saved');
});
gfg(); // Print nothing
gfg(); // Print nothing
gfg(); // Print Saved
輸出:
Saved
範例2:在此示例中,我們嘗試兩次調用該函數,但僅第二次調用。
// Requiring the lodash library
const _ = require("lodash");
// Applying _.after() method
var gfg = _.after(2, function () {
console.log('Successful');
});
gfg(); // Print nothing
gfg(); // Print Successful
輸出:
Successful
相關用法
- Lodash _.method()用法及代碼示例
- Lodash _.uniqWith()用法及代碼示例
- Lodash _.xorWith()用法及代碼示例
- Lodash _.head()用法及代碼示例
- Lodash _.remove()用法及代碼示例
- Lodash _.pullAt()用法及代碼示例
- Lodash _.pullAll()用法及代碼示例
- Lodash _.pull()用法及代碼示例
- Lodash _.nth()用法及代碼示例
- Lodash _.takeRight()用法及代碼示例
- Lodash _.take()用法及代碼示例
- Lodash _.sortedLastIndex()用法及代碼示例
- Lodash _.fromPairs()用法及代碼示例
- Lodash _.differenceWith()用法及代碼示例
- Lodash _.castArray()用法及代碼示例
- Lodash _.cloneDeep()用法及代碼示例
- Lodash _.clone()用法及代碼示例
- Lodash _.sampleSize()用法及代碼示例
- Lodash _.find()用法及代碼示例
注:本文由純淨天空篩選整理自skyridetim大神的英文原創作品 Lodash _.after() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。