07d3998cdc
function f(a, opts) {
let b = opts && 'b' in opts ? opts.b : null;
let c = opts && 'c' in opts ? opts.c : c_default;
...
After:
function f(a, {b = null, c = c_default} = {}) {
...
Note:
- Still reverting to old code when any parameter clashes with reserved JS names (see discussion in https://github.com/dart-lang/dev_compiler/issues/392)
- When a parameter clashes with a Object.prototype property, using a clean default opts value (Object.create(null)).
- Passing opts through in aliased constructors, both for speed/concision and correctness (since default param value semantic is weird there)
BUG=
R=jmesserly@google.com
Review URL: https://codereview.chromium.org/1484263002 .
66 lines
1.1 KiB
Dart
66 lines
1.1 KiB
Dart
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
library methods;
|
|
|
|
class A {
|
|
int x() => 42;
|
|
|
|
int y(int a) {
|
|
return a;
|
|
}
|
|
|
|
int z([num b]) => b;
|
|
|
|
int zz([int b = 0]) => b;
|
|
|
|
int w(int a, {num b}) {
|
|
return a + b;
|
|
}
|
|
|
|
clashWithObjectProperty({constructor}) => constructor;
|
|
clashWithJsReservedName({function}) => function;
|
|
|
|
int get a => x();
|
|
|
|
void set b(int b) {}
|
|
|
|
int _c = 3;
|
|
|
|
int get c => _c;
|
|
|
|
void set c(int c) {
|
|
_c = c;
|
|
}
|
|
}
|
|
|
|
class Bar {
|
|
call(x) => print('hello from $x');
|
|
}
|
|
class Foo {
|
|
final Bar bar = new Bar();
|
|
}
|
|
|
|
test() {
|
|
// looks like a method but is actually f.bar.call(...)
|
|
var f = new Foo();
|
|
f.bar("Bar's call method!");
|
|
|
|
// Tear-off
|
|
A a = new A();
|
|
var g = a.x;
|
|
|
|
// Dynamic Tear-off
|
|
dynamic aa = new A();
|
|
var h = aa.x;
|
|
|
|
// Tear-off of object methods
|
|
var ts = a.toString;
|
|
var nsm = a.noSuchMethod;
|
|
|
|
// Tear-off extension methods
|
|
var c = "".padLeft;
|
|
var r = (3.0).floor;
|
|
}
|