| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library methods; | |
| 6 | |
| 7 class A { | |
| 8 int x() => 42; | |
| 9 | |
| 10 int y(int a) { | |
| 11 return a; | |
| 12 } | |
| 13 | |
| 14 int z([num b]) => b; | |
| 15 | |
| 16 int zz([int b = 0]) => b; | |
| 17 | |
| 18 int w(int a, {num b}) { | |
| 19 return a + b; | |
| 20 } | |
| 21 | |
| 22 int ww(int a, {int b: 0}) { | |
| 23 return a + b; | |
| 24 } | |
| 25 | |
| 26 clashWithObjectProperty({constructor}) => constructor; | |
| 27 clashWithJsReservedName({function}) => function; | |
| 28 | |
| 29 int get a => x(); | |
| 30 | |
| 31 void set b(int b) {} | |
| 32 | |
| 33 int _c = 3; | |
| 34 | |
| 35 int get c => _c; | |
| 36 | |
| 37 void set c(int c) { | |
| 38 _c = c; | |
| 39 } | |
| 40 } | |
| 41 | |
| 42 class Bar { | |
| 43 call(x) => print('hello from $x'); | |
| 44 } | |
| 45 class Foo { | |
| 46 final Bar bar = new Bar(); | |
| 47 } | |
| 48 | |
| 49 test() { | |
| 50 // looks like a method but is actually f.bar.call(...) | |
| 51 var f = new Foo(); | |
| 52 f.bar("Bar's call method!"); | |
| 53 | |
| 54 // Tear-off | |
| 55 A a = new A(); | |
| 56 var g = a.x; | |
| 57 | |
| 58 // Dynamic Tear-off | |
| 59 dynamic aa = new A(); | |
| 60 var h = aa.x; | |
| 61 | |
| 62 // Tear-off of object methods | |
| 63 var ts = a.toString; | |
| 64 var nsm = a.noSuchMethod; | |
| 65 | |
| 66 // Tear-off extension methods | |
| 67 var c = "".padLeft; | |
| 68 var r = (3.0).floor; | |
| 69 } | |
| OLD | NEW |