AT
foo(a, b, c) = bla a b c.
foo(a, b) = foo(a, b, 42).
Теперь третий аргумент
foo по умолчанию -- 42.Size: a a a
AT
foo(a, b, c) = bla a b c.
foo(a, b) = foo(a, b, 42).
foo по умолчанию -- 42.AK
K
AT
AK
function foo(a = 1, b = 2, c = 3) {
console.log(a, b, c);
}
function test(f) {
f();
f(11);
f(11, 22);
f(11, 22, 33);
}
test(foo);1 2 3
11 2 3
11 22 3
11 22 33
AT
[
[
AK
[
AK
AK
function handleIteration(elem, index = undefined) {
console.log(index ? elem + " at " + index : elem);
}
function iterateArray(array, handler) {
for(var i = 0; i < array.length; i++)
handler(array[i], i); // 2 аргумента - индекс есть
}
function iterateInfinite(factory, handler) {
while(result = factory())
handler(result); // 1 аргумент - индекса нет
}МБ
K
a
K
a
K
def, в которую суют поля, отличающиеся от таковых по умолчанию. Щас пример найдуK
{-# language NamedFieldPuns #-}data Opts = Opts { i :: Int, s :: String }
instance Default Opts where
def = Opts 42 "foo"
foo :: Opts -> Bar
foo (Opts { s, i }) = ...
bar = foo def { s = "bar" }a