方法的 Dart lambda 语法在运行时有影响吗?
Has the Dart lambda syntax for method an effect at runtime?
在JavaScript中m1
和m2
有区别:
class A {
m1() { return 123; }
m2 = () => 123;
}
在这里,m1
存储在原型中(它存在于表示 class 的对象中),而 m2
的副本作为 [=] 存储在每个实例中28=]。所以第一种语法在适应的地方更好。
我想知道对于这种代码在Dart中是否有类似的区别:
class A {
int m1() { return 123; }
int m2() => 123;
}
在运行时,m1
和 m2
是否完全等价?
在 Dart 中,没有区别。
The => expr
syntax is a shorthand for { return expr; }
. The =>
notation is sometimes referred to as arrow syntax.
JavaScript 差异是由于历史原因造成的,任何理智的语言都不会对这两种表示法有相同的区别。
在JavaScript中m1
和m2
有区别:
class A {
m1() { return 123; }
m2 = () => 123;
}
在这里,m1
存储在原型中(它存在于表示 class 的对象中),而 m2
的副本作为 [=] 存储在每个实例中28=]。所以第一种语法在适应的地方更好。
我想知道对于这种代码在Dart中是否有类似的区别:
class A {
int m1() { return 123; }
int m2() => 123;
}
在运行时,m1
和 m2
是否完全等价?
在 Dart 中,没有区别。
The
=> expr
syntax is a shorthand for{ return expr; }
. The=>
notation is sometimes referred to as arrow syntax.
JavaScript 差异是由于历史原因造成的,任何理智的语言都不会对这两种表示法有相同的区别。