OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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 /// This library defines the operations that define and manipulate Dart | 5 /// This library defines the operations that define and manipulate Dart |
6 /// classes. Included in this are: | 6 /// classes. Included in this are: |
7 /// - Generics | 7 /// - Generics |
8 /// - Class metadata | 8 /// - Class metadata |
9 /// - Extension methods | 9 /// - Extension methods |
10 /// | 10 /// |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 /// function Foo { function call(...args) { ... } ... return call; }, | 461 /// function Foo { function call(...args) { ... } ... return call; }, |
462 /// class Foo { call(x) { ... } }); | 462 /// class Foo { call(x) { ... } }); |
463 /// ... | 463 /// ... |
464 /// let f = new lib.Foo(); | 464 /// let f = new lib.Foo(); |
465 /// f(42); | 465 /// f(42); |
466 callableClass(callableCtor, classExpr) { | 466 callableClass(callableCtor, classExpr) { |
467 JS('', '#.prototype = #.prototype', callableCtor, classExpr); | 467 JS('', '#.prototype = #.prototype', callableCtor, classExpr); |
468 // We're not going to use the original class, so we can safely replace it to | 468 // We're not going to use the original class, so we can safely replace it to |
469 // point at this constructor for the runtime type information. | 469 // point at this constructor for the runtime type information. |
470 JS('', '#.prototype.constructor = #', callableCtor, callableCtor); | 470 JS('', '#.prototype.constructor = #', callableCtor, callableCtor); |
471 JS('', '#.__proto__ = #.__proto__', callableCtor, classExpr); | 471 JS('', '#.__proto__ = #', callableCtor, classExpr); |
472 return callableCtor; | 472 return callableCtor; |
473 } | 473 } |
474 | 474 |
475 /// Given a class and an initializer method name and a call method, creates a | 475 /// Given a class and an initializer method name and a call method, creates a |
476 /// constructor function with the same name. | 476 /// constructor function with the same name. |
477 /// | 477 /// |
478 /// For example it can be called with `new SomeClass.name(args)`. | 478 /// For example it can be called with `new SomeClass.name(args)`. |
479 /// | 479 /// |
480 /// The constructor | 480 /// The constructor |
481 defineNamedConstructorCallable(clazz, name, ctor) => JS( | 481 defineNamedConstructorCallable(clazz, name, ctor) => JS( |
482 '', | 482 '', |
483 '''(() => { | 483 '''(() => { |
484 ctor.prototype = $clazz.prototype; | 484 ctor.prototype = $clazz.prototype; |
485 // Use defineProperty so we don't hit a property defined on Function, | 485 // Use defineProperty so we don't hit a property defined on Function, |
486 // like `caller` and `arguments`. | 486 // like `caller` and `arguments`. |
487 $defineProperty($clazz, $name, { value: ctor, configurable: true }); | 487 $defineProperty($clazz, $name, { value: ctor, configurable: true }); |
488 })()'''); | 488 })()'''); |
OLD | NEW |