尝试从命令行调用函数,但出现此错误TypeError:fn不是函数

时间:2020-04-09 16:52:47

标签: javascript node.js command-line-parsing

我正在尝试通过解析节点中的命令行参数来调用函数。

#node test.js doSomething print
const fn = process.argv[2];
const val = process.argv[3];

function doSomething(arg) {
    console.log(arg);
}

fn(val);

但是我得到这个错误

fn(val);
^

TypeError: fn is not a function

0 个答案:

没有答案