自己手动编写jsApi
1.用es5实现数组的map方法
1 | Array.prototype.myMap = (fn, context) => { |
2.用es5实现数组的reduce方法
1 | Array.prototype.myReduce = (fn, initialValue) => { |
3.实现call/apply
1 | // 实现apply只要把下面的...args 换成 args |
4.实现对象的Object.create()方法
1 | Object.create = (proto) => { |
5.实现bind方法
1 | Function.prototype.myBind = (context, ...args) => { |
6.实现new关键字
1 | function myNew(fn, ...args) { |
7.实现instanceof的作用
1 | function myInstanceof(left, right) { |
8.实现单例模式
1 | function proxy() { |
`