我试图避免在参数列表中输入长句 这是一个习惯用Scala存档的方式吗?
def createRecaptchaHtml: String = {
def config(s: String) = Play.current.configuration.getString(s).toString()
ReCaptchaFactory.newReCaptcha(config("recaptcha.publicKey") , config("recaptcha.privateKey"), false).createRecaptchaHtml(null, null)
答案 0 :(得分:9)
是的,这种本地方法非常适合该应用。另一种方法是在范围中导入所需的实例方法:
def createRecaptchaHtml: String = {
import Play.current.configuration.getString
ReCaptchaFactory.newReCaptcha(
getString("recaptcha.publicKey").get,
getString("recaptcha.privateKey").get,
false
).createRecaptchaHtml(null, null)
}