Closure
Use case 1: cache data.
In the following example, the inner function getId
referenced the variable id
in outer function createIdGenerator
. The variable id
is memorized and each call to generateId
will return the next id.
1 | function createIdGenerator() { |
event loop
prototype
this
this
in javascript is a very complex concept, and we need a separated post to elaborate it. Here we just give a brief introduction.
promise
async/await
据说async/await底层是借助Promise和generator来实现的,有待学习。