Skip to content

Instantly share code, notes, and snippets.

@nau
Created July 26, 2013 15:01
Show Gist options
  • Save nau/6089585 to your computer and use it in GitHub Desktop.
Save nau/6089585 to your computer and use it in GitHub Desktop.
import org.jscala._
object JScalaExample {
def main(args: Array[String]) {
val js = javascript {
window.setTimeout(() => {
val r = new RegExp("d.*", "g")
def func(i: String) = r.exec(i)
val list = document.getElementById("myList2")
val map = collection.mutable.Map[String, String]()
if (typeof(map) == "string") {
for (idx <- 0 until list.attributes.length) {
val attr = list.attributes.item(idx).asInstanceOf[Attribute]
map(attr.name) = func(attr.textContent).asInstanceOf[String]
}
} else {
val obj = new {
val field = 1
def func2(i: Int) = "string"
}
val links = Array("https://github.com/nau/scala")
for (link <- links) {
include("var raw = 'JavaScript'")
console.log(link + obj.func2(obj.field))
}
window.location.href = links(0).replace("scala", "jscala")
}
}, 1000)
}
println(js.asString)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment