[JavaScript] Declare Function( )

=====(1)
function showText1(lineNumber1) { console.log("Testing Text: " + lineNumber1) };
showText1('Method 1');

=====(2)
var showText2 = new Function('lineNumber2', 'console.log(\'Testing Text: \' + lineNumber2);');
showText2('Method 2');

=====(3)
var showText3 = function (lineNumber3) { console.log('Testing Text: ' + lineNumber3); }
showText3('Method 3');

=====(4)
(function (lineNumber4) { console.log('Testing Text: ' + lineNumber4); }
)('Method 4');

=====(5)
(function (lineNumber5) { console.log('Testing Text: ' + lineNumber5); }
('Method 5'));

=====(6)
void function (lineNumber6) {
    console.log('Testing Text: ' + lineNumber6);
}('Method 6');

=====Note
(1)為函數陳述式, 不管放在前或後, 都可以被執行. 其它為函數運算式則需要先建立後才能呼叫.


showText7('Method 7');
function showText7(lineNumber7) {
    console.log('Testing Text: ' + lineNumber7);
}

留言

這個網誌中的熱門文章

[Python] raw_input() function

[Golang] for