Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 单行节点API初始化_Node.js - Fatal编程技术网

Node.js 单行节点API初始化

Node.js 单行节点API初始化,node.js,Node.js,有时,当我导入节点js模块时,我需要导入并实例化该类。我想用一行代码来完成它(这可能是nodejs的一个非常基本的问题,但我的JavaScript知识有限) 例: 我觉得有一个常量很奇怪,它在我的代码中只用于实例化另一个常量一次。 我想做一些类似的事情: const client = new require('google-auth-library')({ email: 'asd', key: 'abc', scopes: ['https://ww

有时,当我导入节点js模块时,我需要导入并实例化该类。我想用一行代码来完成它(这可能是nodejs的一个非常基本的问题,但我的JavaScript知识有限)

例:

我觉得有一个常量很奇怪,它在我的代码中只用于实例化另一个常量一次。 我想做一些类似的事情:

const client = new require('google-auth-library')({
        email: 'asd',
        key: 'abc',
        scopes: ['https://www.googleapis.com/auth/cloud-platform'],
      });

可能吗?什么是正确的语法?

我不会担心这些小问题,因为从性能角度看,它们无关紧要,而且您可以获得更好的可读性。然而,若你们坚持,那个么你们可以使用下面的代码,但我不会推荐,更不用说麻烦了

const client = new (require('google-auth-library')).JWT({
        email: 'asd',
        key: 'abc',
        scopes: ['https://www.googleapis.com/auth/cloud-platform'],
      });

const client = new (require('google-auth-library')).JWT({
        email: 'asd',
        key: 'abc',
        scopes: ['https://www.googleapis.com/auth/cloud-platform'],
      });