| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // Bind a method to a variable that can be invoked as a function | 5 // Bind a method to a variable that can be invoked as a function |
| 6 | 6 |
| 7 class A { | 7 class A { |
| 8 int a; | 8 int a; |
| 9 | 9 |
| 10 static var func; | 10 static var func; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 Expect.equals(4, f13()); | 117 Expect.equals(4, f13()); |
| 118 | 118 |
| 119 var o14 = new D(14); | 119 var o14 = new D(14); |
| 120 Function f14 = o14.getSuper(); | 120 Function f14 = o14.getSuper(); |
| 121 Expect.equals(14, f14()); | 121 Expect.equals(14, f14()); |
| 122 | 122 |
| 123 // Assign static field to a function and invoke it. | 123 // Assign static field to a function and invoke it. |
| 124 A.func = A.foo; | 124 A.func = A.foo; |
| 125 Expect.equals(4, A.func()); | 125 Expect.equals(4, A.func()); |
| 126 | 126 |
| 127 // bind a function that is possibly native in Javascript. |
| 128 String o15 = 'hithere'; |
| 129 var f15 = o15.substring; |
| 130 Expect.equals('i', f15(1, 2)); |
| 131 |
| 132 var o16 = 'hithere'; |
| 133 var f16 = o16.substring; |
| 134 Expect.equals('i', f16(1, 2)); |
| 135 |
| 136 var f17 = 'hithere'.substring; |
| 137 Expect.equals('i', f17(1, 2)); |
| 127 } | 138 } |
| 128 | 139 |
| 129 static testMain() { | 140 static testMain() { |
| 130 test(); | 141 test(); |
| 131 } | 142 } |
| 132 } | 143 } |
| 133 | 144 |
| 134 main() { | 145 main() { |
| 135 MethodBindingTest.testMain(); | 146 MethodBindingTest.testMain(); |
| 136 } | 147 } |
| OLD | NEW |