gpt4 book ai didi

javascript - 为什么在条件中不检查流密封对象类型属性

转载 作者:行者123 更新时间:2023-11-28 03:54:37 25 4
gpt4 key购买 nike

条件语句中未检查密封对象属性的原因是什么?

例如:

// Create a sealed object type
const o = {
Foo: 'Foo',
};

// Access a non-existent property
// Reports an Error
const fooz = o.Fooz;

// Conditional with non-existent property
// Does not report an error
if (o.Fooz === undefined) {}

澄清一下 - 这是 Flow sealed object

最佳答案

我将此问题发布为 Flow issue 。我收到回复:

Non-existence is not an error within a conditional expression. See the comment from the source.

源评论如下:

Conditional expressions are checked like expressions, except that property accesses are provisionally allowed even when such properties do not exist. This accommodates the common JavaScript idiom of testing for the existence of a property before using that property.

关于javascript - 为什么在条件中不检查流密封对象类型属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47666145/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com