Dart中的patch关键字有什么作用? [英] What does the patch keyword in Dart do?
问题描述
有人可以解释patch关键字的作用吗?例如,在
math_patch.dart
中,我看到
Can someone explain what the patch keyword does? For example, in
math_patch.dart
I see
patch num pow(num x, num exponent) => MathNatives.pow(x, exponent);
patch double atan2(num a, num b) => MathNatives.atan2(a, b);
patch double sin(num x) => MathNatives.sin(x);
patch double cos(num x) => MathNatives.cos(x);
这是什么意思? _patch.dart
文件有什么用途?
What does this mean? What are _patch.dart
files for?
推荐答案
修补程序机制是在内部使用(并且仅供内部
使用,不适用于最终用户)以提供
核心库功能的不同实现。
The patch mechanism is used internally (and is only available internally, not to end users) to provide different implementations of core library functionality.
对于数学库如下所示, lib / math
中与平台无关的
库源将这些方法声明为 external
。
external
方法是从补丁文件获取其实现的。
是VM中 runtime / lib / math_patch.dart
中的补丁文件,其中
提供了实现VM和
中的补丁文件
中的 dart2js
编译器在
lib / compiler / implementation / lib / math_patch中。 dart
,它提供
dart2js
实现。
For the math library that you have below, the platform independent
library source in lib/math
declares these methods as external
.
external
methods get their implementation from a patch file. There
is a patch file in the VM in runtime/lib/math_patch.dart
, which
supplies the implementation for the VM and there is a patch file in
the dart2js
compiler in
lib/compiler/implementation/lib/math_patch.dart
, which supplies the
dart2js
implementation.
The <$分析器可以理解c $ c> external 关键字,并且这种
方式只能将共享部分包含在SDK中,而
工具可以理解。这意味着SDK可以具有 lib / math
,而不是
lib / math / runtime
和 lib / math / dart2js
,这使SDK更加整洁,并使
更易于理解。
The external
keyword is understood by the analyzer and doing it this
way allows only the shared part to be in the SDK and be understood by
the tools. That means that the SDK can have lib/math
instead of having
lib/math/runtime
and lib/math/dart2js
, which makes the SDK cleaner and
easier to understand.
这篇关于Dart中的patch关键字有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!