| 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 part of dart.core; | 5 part of dart.core; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * The base class for all function types. | 8 * The base class for all function types. |
| 9 * | 9 * |
| 10 * A function value, or an instance of a class with a "call" method, is a | 10 * A function value, or an instance of a class with a "call" method, is a |
| 11 * subtype of a function type, and as such, a subtype of [Function]. | 11 * subtype of a function type, and as such, a subtype of [Function]. |
| 12 */ | 12 */ |
| 13 abstract class Function { | 13 abstract class Function { |
| 14 @patch | 14 /** |
| 15 * Dynamically call [function] with the specified arguments. |
| 16 * |
| 17 * Acts the same as calling function with positional arguments |
| 18 * corresponding to the elements of [positionalArguments] and |
| 19 * named arguments corresponding to the elements of [namedArguments]. |
| 20 * |
| 21 * This includes giving the same errors if [function] isn't callable or |
| 22 * if it expects different parameters. |
| 23 * |
| 24 * Example: |
| 25 * Map<Symbol, dynamic> namedArguments = new Map<Symbol, dynamic>(); |
| 26 * namedArguments[const Symbol("f")] = 4; |
| 27 * namedArguments[const Symbol("g")] = 5; |
| 28 * Function.apply(foo, [1,2,3], namedArguments); |
| 29 * |
| 30 * gives exactly the same result as |
| 31 * foo(1, 2, 3, f: 4, g: 5). |
| 32 * |
| 33 * If [positionalArguments] is null, it's considered an empty list. |
| 34 * If [namedArguments] is omitted or null, it is considered an empty map. |
| 35 */ |
| 15 static apply(Function function, | 36 static apply(Function function, |
| 16 List positionalArguments, | 37 List positionalArguments, |
| 17 [Map<Symbol, dynamic> namedArguments]) { | 38 [Map<Symbol, dynamic> namedArguments]) { |
| 18 return Primitives.applyFunction( | 39 return Primitives.applyFunction( |
| 19 function, positionalArguments, | 40 function, positionalArguments, |
| 20 namedArguments == null ? null : _toMangledNames(namedArguments)); | 41 namedArguments == null ? null : _toMangledNames(namedArguments)); |
| 21 } | 42 } |
| 22 | 43 |
| 23 /** | 44 /** |
| 24 * Returns a hash code value that is compatible with `operator==`. | 45 * Returns a hash code value that is compatible with `operator==`. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 41 * | 62 * |
| 42 * Function expressions never give rise to equal function objects. Each time | 63 * Function expressions never give rise to equal function objects. Each time |
| 43 * a function expression is evaluated, it creates a new closure value that | 64 * a function expression is evaluated, it creates a new closure value that |
| 44 * is not known to be equal to other closures created by the same expression. | 65 * is not known to be equal to other closures created by the same expression. |
| 45 * | 66 * |
| 46 * Classes implementing `Function` by having a `call` method should have their | 67 * Classes implementing `Function` by having a `call` method should have their |
| 47 * own `operator==` and `hashCode` depending on the object. | 68 * own `operator==` and `hashCode` depending on the object. |
| 48 */ | 69 */ |
| 49 bool operator==(Object other); | 70 bool operator==(Object other); |
| 50 } | 71 } |
| OLD | NEW |