var leadingThirtysevenList = list.bind(undefined, 37);
This is a code snippet I saw in the manual about what the bind() function does when it passes in the second parameter, in which it passes undefined as a parameter. I have also seen the practice of passing undefined parameters in some frameworks, but I have not been able to find a more complete and clear answer through online searches. I would like to ask teachers to give a detailed answer.
The code you provided, why undefined is passed in, may have nothing to do with my explanation below.
I will mainly talk about some other frameworks; for example, jquery will pass in undefined as a parameter and assign a null value.
That’s because of a bug in js, that is, undefined can be rewritten! ! , yes, you heard it right.
As for why it is dangerous for undefined to be rewritten, look at the following code:
Then what do you think should be done if you want to pass the second parameter and use the default value for the first parameter or it doesn’t matter?
This code is just to implement function curry calling
ECMAScript5.1 15.3.4.4 explains that when the first parameter passed in is null or undefined, the context of the function will point to window (global in node)
The first one is used as a placeholder, but using null will have a better effect than undefined. Generally, I am accustomed to using null to occupy positions.