Wednesday, May 6, 2015

[JavaScript][好文] 在函數裡設定參數預設值

在函數裡設定參數預設值

短摘:
function foo(a, b, c) {
    a = a || "AAA";
    b = b || "BBB";
    c = c || "CCC";

    document.write('a: ' + a + ' ');
    document.write('b: ' + b + ' ');
    document.write('c: ' + c + ' ');
    document.write('<br />');
}
foo(1, '', 3);

No comments:

Post a Comment