Chromium Code Reviews| 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 /** | 14 /** |
| 15 * Dynamically call [function] with the specified arguments. | 15 * Dynamically call [function] with the specified arguments. |
| 16 * | 16 * |
| 17 * Acts the same as calling function with positional arguments | 17 * Acts the same as calling function with positional arguments |
| 18 * corresponding to the elements of [positionalArguments] and | 18 * corresponding to the elements of [positionalArguments] and |
| 19 * named arguments corresponding to the elements of [namedArguments]. | 19 * named arguments corresponding to the elements of [namedArguments]. |
| 20 * | 20 * |
| 21 * This includes giving the same errors if [function] isn't callable or | 21 * This includes giving the same errors if [function] isn't callable or |
| 22 * if it expects different parameters. | 22 * if it expects different parameters. |
| 23 * | 23 * |
| 24 * Example: | 24 * Example: |
| 25 * Map<Symbol, dynamic> namedArguments = new Map<Symbol, dynamic>(); | 25 * ``` |
| 26 * namedArguments[const Symbol("f")] = 4; | 26 * var namedArguments = new Map<Symbol, dynamic>(); |
| 27 * namedArguments[const Symbol("g")] = 5; | 27 * namedArguments[const Symbol("f")] = 4; |
| 28 * Function.apply(foo, [1,2,3], namedArguments); | 28 * namedArguments[const Symbol("g")] = 5; |
| 29 * Function.apply(foo, [1,2,3], namedArguments); | |
| 30 * ``` | |
|
Lasse Reichstein Nielsen
2017/08/23 05:53:31
How about just doing:
Function.apply(foo, [1, 2
floitsch
2017/08/23 18:09:00
done in https://codereview.chromium.org/3002193002
| |
| 29 * | 31 * |
| 30 * gives exactly the same result as | 32 * gives exactly the same result as |
| 31 * foo(1, 2, 3, f: 4, g: 5). | 33 * ``` |
| 34 * foo(1, 2, 3, f: 4, g: 5). | |
| 35 * ``` | |
| 32 * | 36 * |
| 33 * If [positionalArguments] is null, it's considered an empty list. | 37 * If [positionalArguments] is null, it's considered an empty list. |
| 34 * If [namedArguments] is omitted or null, it is considered an empty map. | 38 * If [namedArguments] is omitted or null, it is considered an empty map. |
| 35 */ | 39 */ |
| 36 external static apply(Function function, List positionalArguments, | 40 external static apply(Function function, List positionalArguments, |
| 37 [Map<Symbol, dynamic> namedArguments]); | 41 [Map<Symbol, dynamic> namedArguments]); |
| 38 | 42 |
| 39 /** | 43 /** |
| 40 * Returns a hash code value that is compatible with `operator==`. | 44 * Returns a hash code value that is compatible with `operator==`. |
| 41 */ | 45 */ |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 57 * | 61 * |
| 58 * Function expressions never give rise to equal function objects. Each time | 62 * Function expressions never give rise to equal function objects. Each time |
| 59 * a function expression is evaluated, it creates a new closure value that | 63 * a function expression is evaluated, it creates a new closure value that |
| 60 * is not known to be equal to other closures created by the same expression. | 64 * is not known to be equal to other closures created by the same expression. |
| 61 * | 65 * |
| 62 * Classes implementing `Function` by having a `call` method should have their | 66 * Classes implementing `Function` by having a `call` method should have their |
| 63 * own `operator==` and `hashCode` depending on the object. | 67 * own `operator==` and `hashCode` depending on the object. |
| 64 */ | 68 */ |
| 65 bool operator ==(Object other); | 69 bool operator ==(Object other); |
| 66 } | 70 } |
| OLD | NEW |