【问题标题】:What is the significance of @ operator?@运算符的意义是什么?
【发布时间】:2017-02-03 22:24:15
【问题描述】:

我注意到有些类中有@运算符。

例如,

@TestOn("!vm")
.....

当我进一步挖掘 TestOn 是一个类。

class TestOn {
  /// The expression specifying the platform.
  final String expression;

  const TestOn(this.expression);
}

谁能告诉我@运算符的意义是什么?

【问题讨论】:

  • 认为这就是你的答案:stackoverflow.com/questions/24111378/…。我也很好奇。看起来你可以用另一个类来装饰一个类,比如在 TS 或 ES6 中使用注释。您似乎正在将 const TestOn 应用于上述任何内容,这可能在(可能)测试/运行该函数时用作元数据。或类似的东西。类似于在 TypeScript 中的函数上方添加“@Component”,它赋予它组件(这是一个类)的属性。 Google 确实喜欢他们的注释/装饰器。

标签: dart


【解决方案1】:

@TestOn("!vm") 是一个metadata annotation。它们用于提供有关 Dart 程序中元素的额外信息。

【讨论】:

    猜你喜欢
    • 2015-09-18
    • 2017-03-29
    • 2011-03-16
    • 2011-07-09
    • 2016-07-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多