I am wondering if JavaScript supports writing a function within another function, or nested functions (I read it in a blog). Is this really possible?. In fact, I have used these but am unsure of this concept. I am really unclear on this -- please help!
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
Functions are first class objects that can be:
To build on the example given by Kenny:
Would alert you with 5.
The following is nasty, but serves to demonstrate how you can treat functions like any other kind of object.
Not only can you return a function which you have passed into another function as a variable, you can also use it for calculation inside but defining it outside. See this example:
Yes.
Yes, it is possible to write and call a function nested in another function.
Try this: