質問

Can I declare methods that will be used later in JavaScript similarly to C++ Function prototypes.

役に立ちましたか?

解決

No, there is no such thing as function declarations in Javascript. It doesn't matter what parameters you define in a function, it can be called with any set of values. Example:

function test(a, b) {}

test(); // values are not required for all parameters

test(1, 2, 3, 4); // values are not limited to the number of parameters

Making the code pass stricter validation is another matter. Then you have to define the functions exactly as you use them. The point of the validation in this case is to keep you from misusing the lack of declarations in the language, as it results in code that is harder to follow.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top