zhf.multiple-calls

1.0.5 • Public • Published

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

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

Readme

Keywords

none

Package Sidebar

Install

npm i zhf.multiple-calls

Weekly Downloads

0

Version

1.0.5

License

ISC

Unpacked Size

9.78 kB

Total Files

11

Last publish

Collaborators

  • zhouhuafei