Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 /** | |
| 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; | |
| 10 | |
| 11 /// A metadata annotation that indicates that a Library, Class, or member is | |
|
kevmoo
2015/10/02 20:20:13
Also, expose `dart:js` `wrapClosure` – although I
Jacob
2015/10/03 01:01:08
exported it anyway to avoid extra overhead.
This m
| |
| 12 /// implemented directly in JavaScript. All external members of a class or | |
| 13 /// library with this annotation implicitly have it as well. | |
| 14 /// | |
| 15 /// Specifying [name] customizes the JavaScript name to use. By default the | |
| 16 /// dart name is used. It is not valid to specify a custom [name] for class | |
| 17 /// instance members. | |
| 18 /// | |
| 19 /// Example 1: | |
| 20 /// | |
| 21 /// @Js('google.maps') | |
| 22 /// library maps | |
|
sra1
2015/10/06 21:42:17
semicolon
Jacob
2015/10/13 01:19:22
Done.
| |
| 23 /// | |
| 24 /// external Map get map; | |
| 25 /// | |
| 26 /// @Js("LatLng") | |
| 27 /// class Location { | |
| 28 /// external Location(num lat, num lng); | |
| 29 /// } | |
| 30 /// | |
| 31 /// @Js() | |
| 32 /// class Map { | |
| 33 /// external Map(Location location); | |
| 34 /// external Location getLocation(); | |
| 35 /// } | |
| 36 /// | |
| 37 /// In this example the top level map getter will invoke the JavaScript getter | |
| 38 /// google.maps.map | |
| 39 /// Calls to the Map constructor will be translated to calls to the JavaScript | |
| 40 /// new google.maps.Map(location) | |
| 41 /// Calls to the Location constructor willbe translated to calls to the | |
| 42 /// JavaScript | |
| 43 /// new google.maps.LatLng(lat, lng) | |
| 44 /// because a custom JavaScript name for the Location class. | |
| 45 /// In general, we recommend against using custom JavaScript names whenever | |
| 46 /// possible as it is easier for users if the JavaScript names and Dart names | |
| 47 /// are consistent. | |
| 48 /// | |
| 49 /// Example 2: | |
| 50 /// library utils; | |
| 51 /// | |
| 52 /// @Js("JSON.stringify") | |
| 53 /// external String stringify(obj); | |
| 54 /// | |
| 55 /// @Js() | |
| 56 /// void debugger(); | |
| 57 /// | |
| 58 /// In this example no custom JavaScript namespace is specified. | |
| 59 /// Calls to debugger map to calls to JavaScript | |
| 60 /// self.debugger() | |
| 61 /// Calls to stringify map to calls to | |
| 62 /// JSON.stringify(obj) | |
| 63 class Js { | |
| 64 final String name; | |
| 65 const Js([this.name]); | |
| 66 } | |
| OLD | NEW |