| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 #library('X'); |
| 6 #native('NativeNamedConstructors1FrogTest.js'); // Defines JS constructor 'A'. |
| 7 |
| 8 // The native class has several constructors which partition the behaviour of |
| 9 // the JS constructor function into several well-typed Dart constructors. |
| 10 |
| 11 class A native "A" { |
| 12 |
| 13 // factory constructors allow us to do computation ahead of the allocation. |
| 14 factory A(int len) { return _construct(len); } |
| 15 |
| 16 factory A.fromString(String s) { |
| 17 return _construct(s.length); // convert string to int. |
| 18 } |
| 19 |
| 20 // Helper that does the actual allocation and construction. |
| 21 static A _construct(v) native @'return new A(v);'; |
| 22 |
| 23 foo() native 'return this._x;'; |
| 24 } |
| 25 |
| 26 main() { |
| 27 var a1 = new A(100); |
| 28 var a2 = new A.fromString('Hello'); |
| 29 |
| 30 Expect.equals(100, a1.foo()); |
| 31 Expect.equals(5, a2.foo()); |
| 32 } |
| OLD | NEW |