简体   繁体   English

奇怪的(Webpack?)错误“ TypeError:Object(…)不是函数”

[英]Strange (webpack?) error “TypeError: Object(…) is not a function”

Following syntax 遵循语法

const INITIAL_STATE = {
  userIsActive: getAccount() ? getAccount().status === "open" : false
};

Causes browser to throw TypeError: Object(...) is not a function error, I pinpointed it to being syntax specific, getAccount() just returns object like 导致浏览器抛出TypeError: Object(...) is not a function错误,我将其精确定位为特定于语法,getAccount()只是返回对象,例如

{
  status: "open"
}

Changing to this works perfectly fine, even returns correct data 更改为此功能可以很好地工作,甚至返回正确的数据

const accStatus = () => {
  try {
    return getAccount() ? getAccount().status === "open" : false;
  } catch (e) {
    console.error(e);
    return false;
  }
};

const INITIAL_STATE = {
  userIsActive: accStatus
};

but I don't understand why it doesn't work in the first place? 但我不明白为什么它首先不起作用?

EDIT: That catch statement is not triggered, which is odd 编辑:不触发catch语句,这很奇怪

In the first example, userIsActive is a boolean value, whereas in the second example it is a function that returns the boolean. 在第一个示例中, userIsActive是一个布尔值,而在第二个示例中,它是一个返回布尔值的函数。 This will probably work: 这可能会起作用:

const INITIAL_STATE = {
  userIsActive: () => getAccount() ? getAccount().status === "open" : false
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 webpack 4 TypeError:“ Object(…)不是函数” - webpack 4 TypeError: “Object(…) is not a function” Uncaught TypeError: Object(...) is not a function 当与 WebPack 4 捆绑时 - Uncaught TypeError: Object(...) is not a function when bundling with WebPack 4 奇怪的“未捕获的TypeError:字符串不是函数”错误 - Strange “Uncaught TypeError: String is not a function” error Webpack 编译错误:TypeError: __WEBPACK_IMPORTED_MODULE_1__ ... is not a function - Webpack compile error: TypeError: __WEBPACK_IMPORTED_MODULE_1__ … is not a function 奇怪的 node.js 错误:TypeError: Object #<Object> 没有方法“开” - Strange node.js error: TypeError: Object #<Object> has no method 'on' ReactJS 错误类型错误:对象(…)不是 function - ReactJS error TypeError: Object(…) is not a function TypeError: Object(...) is not a function 错误在 useAccordianToggle - TypeError: Object(…) is not a function error in useAccordianToggle 带有 babel、typescript 和 webpack 的简单库 - TypeError: (...) is not a function; 在 Object。<anonymous></anonymous> - Simple library with babel, typescript and webpack - TypeError: (…) is not a function; at Object.<anonymous> Uncaught TypeError: Object(…) is not a function after update webpack resolve.modules - Uncaught TypeError: Object(…) is not a function after updating webpack resolve.modules (WebPack) TypeError: Object is not a function or its return value is not iterable - (WebPack) TypeError: Object is not a function or its return value is not iterable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM