简体   繁体   English

Flex / ActionScript3:关键字“ with”隐藏拼写错误的属性名称

[英]Flex/ActionScript3: keyword “with” hides misspelled property names

In Flex 3, 在Flex 3中,

var anInstance : MyClass = new MyClass();
with (anInstance)
{
    property1 = "fred";
    property2 = 5;
    propert3 = 7;
}

does NOT flag "propert" as a non-existent property name. 不会将“ propert”标记为不存在的属性名称。 I thought this was a remainder of the evil JavaScript object behavior (referring to a property name of an object implicitly creates it), but it seems to be a side-effect of the "with". 我以为这是邪恶的JavaScript对象行为的剩余部分(指的是对象的属性名称隐式创建了它),但这似乎是“ with”的副作用。

This makes me very sad as the "with" was a little reminder of Delphi (except it works correctly there). 这让我非常难过,因为“ with”有点像Delphi的提醒(除非它在那里正确工作)。

Am I missing something here? 我在这里想念什么吗?

From reading the documentation : 通过阅读文档

Actionscript apparently bubbles out for scope resolution on embedded variables (not surprising, since the syntax doesn't require an explicit dereference symbol like "." or "->" to indicate which variable names should be "withed".) So you effectively are creating a variable at global scope named propert3. Actionscript显然会冒泡地对嵌入式变量进行范围解析(这并不奇怪,因为语法不需要像“。”或“->”这样的显式解除引用符号来指示应“使用”哪些变量名。)因此,您有效地做到了在全局范围内创建一个名为propert3的变量。


EDIT after thinking about why this "problem" exists - 考虑这个“问题”为何存在后进行编辑-

Javascript is the epitome of non-strict typing. Javascript是非严格键入的缩影。 And Actionscript, being a strict superset of Javascript, can't enforce strict typing except as declared by its own extensions to the language - which means it must support untyped variables. 而且,Actionscript是Javascript的严格超集,除非通过其自己的语言扩展声明,否则不能强制执行严格的类型化-这意味着它必须支持未类型化的变量。

Some classes are dynamic (eg movieclip) and can have properties added to them at runtime: 一些类是动态的(例如movieclip),并且可以在运行时添加属性:

http://flexblog.faratasystems.com/?p=95 http://flexblog.faratasystems.com/?p=95

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM