سؤال

I'm trying to get the following code from scala-js/test/src/test/scala/scala/scalajs/test/jsinterop/DictionaryTest.scala to run in the Browser in a Scala.js project.

import scala.scalajs.js

val obj = js.eval("var dictionaryTest13 = 
     { a: 'Scala.js', b: 7357 }; dictionaryTest13;")
val dict = obj.asInstanceOf[js.Dictionary[js.Any]]
var propCount = 0
var propString = ""

for (prop <- js.Dictionary.propertiesOf(dict)) {
  propCount += 1
  propString += dict(prop)
}
// g.console.log(...)

It gives me: java.lang.RuntimeException: stub

How can I get this to work and make use of bracket access, e.g. to run through a json Object given from js to scala.js, in analogy to the js pattern: for(i in obj) {obj[i]} ?

That serves the trivial purpose to iterate in a over json datastructure in a way that is not bound to specific attributes.

هل كانت مفيدة؟

المحلول

To sum up the discussion:

The OP's code works with Scala.js 0.4.0 in the browser. However, it does not work in the REPL (through sbt), since Scala.js does not support the REPL.

The sbt plugin will issue a warning in the future if the REPL is used.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top