How can I read a text file with scala.js?
问题 Basically I'm trying to figure out what I need to pass to the onload() method def selectedFile(e: ReactEventI) = { val reader = new dom.FileReader() reader.readAsText(e.currentTarget.files.item(0)) reader.onload( ) } 回答1: You can assign a lambda to the onload handler: reader.onload = (e: UIEvent) => { // Cast is OK, since we are calling readAsText val contents = reader.result.asInstanceOf[String] println(contents) } 回答2: Idiomatic Scala, with error handling Instead of using callbacks, I