OLD | NEW |
1 // Copyright (c) 2013, 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 /** | 5 /// Allows interoperability with Javascript APIs. |
6 * The js library allows Dart library authors to export their APIs to JavaScript | |
7 * and to define Dart interfaces for JavaScript objects. | |
8 */ | |
9 library js; | 6 library js; |
10 | 7 |
11 export 'dart:js' show allowInterop, allowInteropCaptureThis; | 8 export 'dart:js' show allowInterop, allowInteropCaptureThis; |
12 | 9 |
13 /// A metadata annotation that indicates that a Library, Class, or member is | 10 /// A metadata annotation that indicates that a Library, Class, or member is |
14 /// implemented directly in JavaScript. All external members of a class or | 11 /// implemented directly in JavaScript. All external members of a class or |
15 /// library with this annotation implicitly have it as well. | 12 /// library with this annotation implicitly have it as well. |
16 /// | 13 /// |
17 /// Specifying [name] customizes the JavaScript name to use. By default the | 14 /// Specifying [name] customizes the JavaScript name to use. By default the |
18 /// dart name is used. It is not valid to specify a custom [name] for class | 15 /// dart name is used. It is not valid to specify a custom [name] for class |
19 /// instance members. | 16 /// instance members. |
20 /// | |
21 /// Example 1: | |
22 /// | |
23 /// @Js('google.maps') | |
24 /// library maps; | |
25 /// | |
26 /// external Map get map; | |
27 /// | |
28 /// @Js("LatLng") | |
29 /// class Location { | |
30 /// external Location(num lat, num lng); | |
31 /// } | |
32 /// | |
33 /// @Js() | |
34 /// class Map { | |
35 /// external Map(Location location); | |
36 /// external Location getLocation(); | |
37 /// } | |
38 /// | |
39 /// In this example the top level map getter will invoke the JavaScript getter | |
40 /// google.maps.map | |
41 /// Calls to the Map constructor will be translated to calls to the JavaScript | |
42 /// new google.maps.Map(location) | |
43 /// Calls to the Location constructor willbe translated to calls to the | |
44 /// JavaScript | |
45 /// new google.maps.LatLng(lat, lng) | |
46 /// because a custom JavaScript name for the Location class. | |
47 /// In general, we recommend against using custom JavaScript names whenever | |
48 /// possible as it is easier for users if the JavaScript names and Dart names | |
49 /// are consistent. | |
50 /// | |
51 /// Example 2: | |
52 /// library utils; | |
53 /// | |
54 /// @Js("JSON.stringify") | |
55 /// external String stringify(obj); | |
56 /// | |
57 /// @Js() | |
58 /// void debugger(); | |
59 /// | |
60 /// In this example no custom JavaScript namespace is specified. | |
61 /// Calls to debugger map to calls to JavaScript | |
62 /// self.debugger() | |
63 /// Calls to stringify map to calls to | |
64 /// JSON.stringify(obj) | |
65 class Js { | 17 class Js { |
66 final String name; | 18 final String name; |
67 const Js([this.name]); | 19 const Js([this.name]); |
68 } | 20 } |
OLD | NEW |