【问题标题】:TypeError: Class constructor CryptoFactory cannot be invoked without 'new'TypeError:没有'new'就不能调用类构造函数CryptoFactory
【发布时间】:2018-06-12 07:46:37
【问题描述】:

我要使用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'

【问题讨论】:

  • 从错误信息来看,链接页面是错误的,错误是明确告诉你该怎么做。你试过这样做吗?
  • 它看起来像一个类,你必须这样做: const factory = new CryptoFactory(context); const signer = facory.newSigner(privateKey);
  • const signer = new CryptoFactory(context).newSigner(privateKey)

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


【解决方案1】:

由于错误状态,您应该更改:

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

到:

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

【讨论】:

    猜你喜欢
    • 2018-11-12
    • 2019-04-21
    • 2021-05-17
    • 2021-12-27
    • 1970-01-01
    • 1970-01-01
    • 2020-01-04
    • 2021-05-24
    • 2020-11-27
    相关资源
    最近更新 更多