This tiny example demonstrates the use of Ceylon [service providers][] in the JavaScript environment. Service providers are an abstraction of, and [interoperate][] with, Java's [service loaders][], but are not tied to the Java platform, and can even work cross-platform.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import ceylon.time { Instant, DateTime } | |
| shared void run() { | |
| dynamic { | |
| //create a JavaScript Date | |
| dynamic date = Date(); | |
| print(date); | |
| //convert it to a Ceylon DateTime | |
| DateTime dt = Instant(date.getTime()).dateTime(); | |
| print(dt); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import ceylon.collection { | |
| ArrayList | |
| } | |
| "Create a typesafe proxy for the given [[instance]], that | |
| intercepts method calls and attribute evaluations." | |
| Instance proxy<Instance>(Instance instance)(call, get) { | |
| "Intercepts method invocations. Delegate to the method | |
| of [[target]] by calling `method(args)`." |
This little example application demonstrates the use of Ceylon as an alternative to client-side JavaScript. In particular, the example shows:
- a simple, typesafe, object-oriented program,
- dependence on an external [cross-platform math module][xmath] written in Ceylon and hosted on
OlderNewer