函式

參數、arguments、方法與函數式寫法。

7 / 7 題 · 依票數排序

7.7k

var functionName = function() {} vs function functionName() {}

I've recently started maintaining someone else's JavaScript code. I'm fixing bugs, adding features and also trying to tidy up the code and make it more consistent. The previous de…

2008javascriptfunctionmethodssyntax·3 重點答案·1.2M 次瀏覽
7.6k

How do JavaScript closures work?

How would you explain JavaScript closures to someone with a knowledge of the concepts they consist of (for example functions, variables and the like), but does not understand clos…

2008javascriptfunctionvariablesscopeclosures·3 重點答案·1.6M 次瀏覽
3.5k

What is the difference between call and apply?

What is the difference between using Function.prototype.apply() and Function.prototype.call() to invoke a function? const func = function() { alert("Hello world!"); }; func.apply(…

2009javascriptfunctionperformance·3 重點答案·844k 次瀏覽
2.7k

Set a default parameter value for a JavaScript function

I would like a JavaScript function to have optional arguments which I set a default on, which get used if the value isn't defined (and ignored if the value is passed). In Ruby you…

2009javascriptfunctionparametersargumentsdefault-parameters·3 重點答案·1.5M 次瀏覽
2.5k

JavaScript check if variable exists (is defined/initialized)

Which method of checking if a variable has been initialized is better/correct? (Assuming the variable could hold anything (string, int, object, function, etc.)) if (elem) { // or…

2011javascriptfunctionvariablesinitializationundefined·3 重點答案·2.7M 次瀏覽
2.2k

What is the scope of variables in JavaScript?

What is the scope of variables in javascript? Do they have the same scope inside as opposed to outside a function? Or does it even matter? Also, where are the variables stored if…

2009javascriptfunctionvariablesscopevar·3 重點答案·586k 次瀏覽
1.8k

What does "javascript:void(0)" mean?

<a href="javascript:void(0)" id="loginlink">login</a> I've seen such href s many times, but I don't know what exactly that means.

2009javascriptvoid·3 重點答案·2.9M 次瀏覽