Ordenación de parámetros de la función predeterminada
Leyendo a través deest, Llegué al bit en valores predeterminados para argumentos de función:
fill = (container, liquid = "coffee") ->
"Filling the #{container} with #{liquid}..."
Eso está bien, pero luego probé esto:
fill = (container="mug", liquid = "coffee") ->
"Filling the #{container} with #{liquid}..."
alert fill(liquid="juice")
y recibió la alerta inesperada con"Filling the juice with coffee..."
. Entonces probé esto:
fill = (container="mug", liquid = "coffee") ->
"Filling the #{container} with #{liquid}..."
alert fill(null, "juice")
Y funcionó. Sin embargo, no es bonito. ¿Hay una mejor manera, o esta es la forma idiomática de hacer esto?