在Kotlin中 使用js 函数
程序员文章站
2022-05-07 18:16:39
在Kotlin中 使用js 函数 ......
在Kotlin中 使用js 函数
import javax.script.Invocable import javax.script.ScriptEngineManager fun main(args: Array<String>) { val engine = ScriptEngineManager().getEngineByName("nashorn") val js = """ function rebate(price, sale_count) { if(sale_count > 30) return price * 10 / 100; if(sale_count > 20) return price * 20 / 100; return price * 30 / 100; } """ engine.eval(js) val invocable = engine as Invocable val res = invocable.invokeFunction("rebate", 100, 200) println(res) }
上一篇: AIOT赋能智能家居开启全屋智能,单品到场景思维转变问题仍旧不少
下一篇: 生孩子居然有这样报喜