示例1:
import scala.scalajs.js.Dynamic.{global => g}
val image1 = g.require("./images/thumbnails/like.png")
scala 2.11.8 - fastOptJS输出:
this.image1$1 = require("./images/thumbnails/like.png");
scala 2.12.0 - fastOptJS输出:
this.image1$1 = require(($m_sjs_js_Any$(), "./images/thumbnails/like.png"));
示例2:
import scala.scalajs.js.Dynamic.{global => g}
@inline def load[T](lib: String): T = g.require(lib).asInstanceOf[T]
@inline def loadDynamic(lib: String): js.Dynamic = load[js.Dynamic](lib)
val image2 = loadDynamic("./images/thumbnails/like.png")
scala 2.11.8 - fastOptJS输出:
this.image2$1 = require("./images/thumbnails/like.png");
scala 2.12.0 - fastOptJS输出:
this.image2$1 = ($m_Lsri_mobile_package$all$(), require(($m_sjs_js_Any$(), "./images/thumbnails/like.png")));
Scala.js版本:0.6.13
答案 0 :(得分:2)
这是Scala.js优化器的已知低效率,其代码由2.12生成。它是filed here,它有a pending fix there。请注意,生成的代码仍然是正确的,尽管效率很低。