Skip to content

Instantly share code, notes, and snippets.

@ceylonwebide
Created September 26, 2015 18:28
Show Gist options
  • Save ceylonwebide/d5ac55d0a6c2748533b9 to your computer and use it in GitHub Desktop.
Save ceylonwebide/d5ac55d0a6c2748533b9 to your computer and use it in GitHub Desktop.
EXAMPLE: Interoperability
//$webrun_wrapped
shared void run() {
// The JVM backend of the Ceylon compiler provides good
// interoperability with Java, so that programs can use the JDK.
// Interoperability with JavaScript is also provided, mainly
// through "dynamic" blocks. Compile-time checks are relaxed in
// these blocks (of course this can result in erros at runtime).
dynamic {
dynamic doc = window.parent.document;
dynamic nodes = doc.getElementsByTagName("A");
Integer nodesLength = nodes.length;
for (i in 0..nodesLength-1) {
dynamic elem = nodes.item(i);
String oldText = elem.textContent;
print(oldText);
if (oldText.startsWith("*") && oldText.endsWith("*")) {
elem.textContent = oldText[1:oldText.size-2];
} else {
elem.textContent = "*``oldText``*";
}
}
print("-- Run again to toggle --");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment