TypeError:如果没有' new',则无法调用类构造函数CryptoFactory。

时间:2018-06-12 07:46:38

标签: javascript node.js ecmascript-6 ecmascript-5 hyperledger-sawtooth

我想使用sawtooth-sdk和指南代码(https://sawtooth.hyperledger.org/docs/core/releases/latest/_autogen/sdk_submit_tutorial_js.html):

const {createContext, CryptoFactory} = require('sawtooth-sdk/signing')

const context = createContext('secp256k1')
const privateKey = context.newRandomPrivateKey()
const signer = CryptoFactory(context).newSigner(privateKey)

但错误:

TypeError: Class constructor CryptoFactory cannot be invoked without 'new'

1 个答案:

答案 0 :(得分:1)

如错误所述,您应该更改:

const signer = CryptoFactory(context).newSigner(privateKey)

为:

const signer = (new CryptoFactory(context)).newSigner(privateKey)