Last active
September 9, 2016 13:27
-
-
Save sjrd/6dc54785b831c099cb43e3ec761db7ad to your computer and use it in GitHub Desktop.
Scala 2.12.0-RC1's new inference improves JS interop!
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
package helloworld | |
import scala.scalajs.js | |
import js.| | |
import js.annotation._ | |
@ScalaJSDefined | |
trait Foo extends js.Object { | |
val bar: Int | String | |
val baz: js.UndefOr[Int] | |
val f: js.Function1[Int, Int] | |
} | |
@ScalaJSDefined | |
class Foobar extends Foo { | |
val bar = 5 | |
val baz = 6 | |
val f = (x: Int) => x + 1 | |
} | |
object HelloWorld extends js.JSApp { | |
def main() { | |
val foobar: Foo = new Foobar | |
println(foobar.bar) | |
println(foobar.baz) | |
println(foobar.f) | |
println(foobar.f(3)) | |
val obj = new Foo { | |
val bar = "hello" | |
val baz = js.undefined | |
val f = x => x * 2 | |
} | |
println(obj.bar) | |
println(obj.baz) | |
println(obj.f) | |
println(obj.f(3)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment