【发布时间】:2011-07-11 10:30:38
【问题描述】:
通读this,我开始了解函数参数的默认值:
fill = (container, liquid = "coffee") ->
"Filling the #{container} with #{liquid}..."
这很好,但后来我尝试了这个:
fill = (container="mug", liquid = "coffee") ->
"Filling the #{container} with #{liquid}..."
alert fill(liquid="juice")
并通过"Filling the juice with coffee..." 收到意外警报。所以我尝试了这个:
fill = (container="mug", liquid = "coffee") ->
"Filling the #{container} with #{liquid}..."
alert fill(null, "juice")
它奏效了。虽然不漂亮。有没有更好的方法,或者这是惯用的方法?
【问题讨论】:
-
长得丑或吃起来很有趣,很难打
标签: coffeescript