Javascript:传递带有参数作为参数的函数并获取此参数

时间:2019-03-27 07:56:57

标签: javascript ecmascript-6

我正在尝试编写一些js函数的验证。

想法:我具有检查功能,将检查的功能对象传递给它,在此请确保一切正常(或不正确)。我不想单独传递参数,而只传递函数对象。 我怎样才能做到这一点?

现在,我不得不满足于两个用于检查功能的参数-func obj和func参数

那就是我想要的:

function checkFunction(func) {
    console.log(func.name);
    console.log(func.arguments);
    // validate something
}

function checkedFunction(a, b, c) {
    checkFunction(checkedFunction...);
    // do something
}

这就是我现在拥有的:

function checkFunction(func, args) {
    console.log(func.name);
    console.log(args);
    // validate something
}

function checkedFunction(a, b, c) {
    checkFunction(checkedFunction, arguments);
    // do something;
}

0 个答案:

没有答案