[英]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.