程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Javascript ES6 TypeError:如果没有“ new”,则无法调用类构造函数Client大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决Javascript ES6 TypeError:如果没有“ new”,则无法调用类构造函数Client?

开发过程中遇到Javascript ES6 TypeError:如果没有“ new”,则无法调用类构造函数Client的问题如何解决?下面主要结合日常开发的经验,给出你关于Javascript ES6 TypeError:如果没有“ new”,则无法调用类构造函数Client的解决方法建议,希望对你解决Javascript ES6 TypeError:如果没有“ new”,则无法调用类构造函数Client有所启发或帮助;

问题在于该类扩展了本机ES6类,并通过Babel转换为ES5。转译的类至少在没有其他措施的情况下不能扩展本机类。

class TranspiledFoo extends Nativebar {
  constructor() {
    super();
  }
}

导致类似

function TranspiledFoo() {
  var _this = Nativebar.call(this) || this;
  return _this;
}
// prototypically inherit from Nativebar

由于ES6类应该只调用newNativebar.call在错误的结果。

ES6类在任何最新的Node版本中均受支持,不应进行编译。es2015应该从Babel配置中排除,最好使用env预设设置为nodetarget。

解决方法

我有一门用Javascript ES6编写的类。当我尝试执行nodemon命令时,我总是会看到此错误TypeError: Classconstructor Client cAnnot be invoked without 'new'

完整错误如下所述:

/Users/akshaysood/Blockchain/fabricSDK/dist/application/transaction.js:45
        return (0,_possibleConstructorReturn3.default)(this,(FBClient.__proto__ || (0,_getPrototypeOf2.default)(FBClient)).call(this,props));
                                                                                                                              ^

TypeError: Class constructor Client cAnnot be invoked without 'new'
    at new FBClient (/Users/akshaysood/Blockchain/fabricSDK/dist/application/transaction.js:45:127)
    at Object.<anonymous> (/Users/akshaysood/Blockchain/fabricSDK/dist/application/transaction.js:195:14)
    at Module._compile (module.js:641:30)
    at Object.Module._extensions..js (module.js:652:10)
    at Module.load (module.js:560:32)
    at trymoduleLoad (module.js:503:12)
    at Function.Module._load (module.js:495:3)
    at Module.require (module.js:585:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/akshaysood/Blockchain/fabricSDK/dist/routes/users.js:11:20)

我想做的是,我创建了一个类,然后创建了该类的实例。然后,我试图导出该变量。

类结构定义如下:

class FBClient extends FabricClient{

    constructor(props){
        super(props);
    }

<<< FUNCTIONS >>>

}

我如何尝试导出变量->

var client = new FBClient();
client.loadFromConfig(config);

export default client = client;

您可以在此处找到完整的代码>
https://hastebin.com/kecacenita.js
Babel生成的代码>
https://hastebin.com/fabewecumo.js

大佬总结

以上是大佬教程为你收集整理的Javascript ES6 TypeError:如果没有“ new”,则无法调用类构造函数Client全部内容,希望文章能够帮你解决Javascript ES6 TypeError:如果没有“ new”,则无法调用类构造函数Client所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。