JavaScript - ' x'不是功能

发布于 2025-02-09 17:34:08 字数 218 浏览 1 评论 0原文

在我的JavaScript文件中,我正在调用函数b内部功能a。我得到以下错误

b不是函数

如何解决此错误?

exports.createRecord = function A() {
  B();

};

exports.B = () =>{
}

In my javascript file I am calling function B inside function A. I get the following error

B is not a function.

How can I resolve this error?

exports.createRecord = function A() {
  B();

};

exports.B = () =>{
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独夜无伴 2025-02-16 17:34:08

将属性分配给对象不会将该属性的名称作为独立标识符。出于类似的原因,以下内容也会失败:

const obj = {
  fn() {
    console.log('hi');
  }
};
fn();

Module.Exports只是具有相同行为的对象。

要么

exports.createRecord = function A() {
  exports.B();
};

exports.createRecord = function A() {
  B();
};

const B = () => {
};
exports.B = B;

Assigning a property to an object does not put that property's name into scope as a standalone identifier. For similar reasons, the following will fail too:

const obj = {
  fn() {
    console.log('hi');
  }
};
fn();

And module.exports is just an object with the same sort of behavior.

Either do

exports.createRecord = function A() {
  exports.B();
};

or

exports.createRecord = function A() {
  B();
};

const B = () => {
};
exports.B = B;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文