OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 * An [Expando] allows adding new properties to objects. | 8 * An [Expando] allows adding new properties to objects. |
9 * | 9 * |
10 * Does not work on numbers, strings, booleans or null. | 10 * Does not work on numbers, strings, booleans or null. |
11 * | 11 * |
12 * An `Expando` does not hold on to the added property value after an object | 12 * An `Expando` does not hold on to the added property value after an object |
13 * becomes inaccessible. | 13 * becomes inaccessible. |
14 * | 14 * |
15 * Since you can always create a new number that is identical to an existing | 15 * Since you can always create a new number that is identical to an existing |
16 * number, it means that an expando property on a number could never be | 16 * number, it means that an expando property on a number could never be |
17 * released. To avoid this, expando properties cannot be added to numbers. | 17 * released. To avoid this, expando properties cannot be added to numbers. |
18 * The same argument applies to strings, booleans and null, which also have | 18 * The same argument applies to strings, booleans and null, which also have |
19 * literals that evaluate to identical values when they occur more than once. | 19 * literals that evaluate to identical values when they occur more than once. |
20 * | 20 * |
21 * There is no restriction on other classes, even for compile time constant | 21 * There is no restriction on other classes, even for compile time constant |
22 * objects. Be careful if adding expando properties to compile time constants, | 22 * objects. Be careful if adding expando properties to compile time constants, |
23 * since they will stay alive forever. | 23 * since they will stay alive forever. |
24 */ | 24 */ |
25 class Expando<T> { | 25 class Expando<T> { |
26 | |
27 /** | 26 /** |
28 * The name of the this [Expando] as passed to the constructor. If | 27 * The name of the this [Expando] as passed to the constructor. If |
29 * no name was passed to the constructor, the name is [:null:]. | 28 * no name was passed to the constructor, the name is [:null:]. |
30 */ | 29 */ |
31 final String name; | 30 final String name; |
32 | 31 |
33 /** | 32 /** |
34 * Creates a new [Expando]. The optional name is only used for | 33 * Creates a new [Expando]. The optional name is only used for |
35 * debugging purposes and creating two different [Expando]s with the | 34 * debugging purposes and creating two different [Expando]s with the |
36 * same name yields two [Expando]s that work on different properties | 35 * same name yields two [Expando]s that work on different properties |
(...skipping 16 matching lines...) Expand all Loading... |
53 external T operator [](Object object); | 52 external T operator [](Object object); |
54 | 53 |
55 /** | 54 /** |
56 * Sets the value of this [Expando]'s property on the given | 55 * Sets the value of this [Expando]'s property on the given |
57 * object. Properties can effectively be removed again by setting | 56 * object. Properties can effectively be removed again by setting |
58 * their value to null. | 57 * their value to null. |
59 * | 58 * |
60 * The object must not be a number, a string, a boolean or null. | 59 * The object must not be a number, a string, a boolean or null. |
61 */ | 60 */ |
62 external void operator []=(Object object, T value); | 61 external void operator []=(Object object, T value); |
63 | |
64 } | 62 } |
OLD | NEW |