- Custom native events
- Create a custom event:
const myEvent = new Event()
,new CustomEvent()
,document.createEvent('CustomEvent')
- Listening for custom events:
document.addEventListener('myEvent', callback)
- Triggering custom events:
document.dispatchEvent(myEvent)
- Create a custom event:
- Promise
- The short version
Promise
(Asynchronous is not supported) - handwritten
Promise
(resolve
,reject
,then
) - implementation
Promise.all()
- implementation
Promise.race()
- implementation
Promise
Asynchronous scheduler
- The short version
- Anti-shake and throttling
- Image stabilization
- The throttle
- Anti-shake + throttling (anti-shake that must be triggered)
- Shallow copy and deep copy
- Handwritten shallow copy
Object.assign
- Shallow copy Other methods:
concat()
,slice()
,[...arr]
- Handwritten deep copy
JSON.parse(JSON.stringify())
- The Lodash
_.cloneDeep()
- JQuery
$.extend()
- call+bind+apply
- native
call
And handwrittencall
- native
bind
And handwrittenbind
- native
apply
And handwrittenapply
- native
- JSONP
- Rationale: Use
script
Of the labelsrc
There are no cross-domain constraints to complete the implementation - Pros and cons: Only
GET
; Good compatibility - Simple implementation: Pass
url, params, callbackKey, callback
To define theJSONP()
Method parameters - Consider multiple calls: Add array save based on simple implementation
callback
The return of
- Rationale: Use
- new
- Three lines of code handwritten
new
- handwritten
new
Five characteristics of the - Full version handwriting
new
- Three lines of code handwritten
- other
Object.create()
- ES5 implements class inheritance
instanceof
- Corrification: Beg
add(1)(2)(3)
- The iterator
- Ajax
- Array flattening: hand-torn,
flat()
,reduce()
- Array deduplication: hand tear,
Set
,filter()
- other