Skip to content

Latest commit

 

History

History
30 lines (27 loc) · 993 Bytes

readme.md

File metadata and controls

30 lines (27 loc) · 993 Bytes

至少调用多次才会触发函数

const multipleCalls = require('zhf.multiple-calls');

// 传入正常参数
let isTrigger = false;
const mulCalls = multipleCalls(3, function (result) {
    isTrigger = true;
    console.log('result', result); // result { a: { a: 1 }, b: { b: 2 }, c: { c: 3 } }
});
mulCalls('a', {a: 1}); // isTrigger is false
mulCalls('b', {b: 2}); // isTrigger is false
mulCalls('c', {c: 3}); // isTrigger is true

// 参入非法参数时,第一参数非法会被纠正成1,第二参数非法会被纠正成空函数
let isTrigger2 = false;
const mulCalls2 = multipleCalls('非法参数', function (result) {
    isTrigger2 = true;
    console.log('result', result); // result { a: { a: 1 } }
});
mulCalls2('a', {a: 1}); // isTrigger2 is true

// 传入正常参数
let isTrigger3 = false;
const mulCalls3 = multipleCalls(1, function (result) {
    isTrigger3 = true;
    console.log('result', result); // result {}
});
mulCalls3(); // isTrigger3 is true