摘要:
实现bind 需要注意的是要考虑作为构造函数的case 构造函数会指定this为new出来的实例对象,此时bind指定的目标无效 /** * fn.bind(context) * Function.bind(this: Function, thisArg: any, ...argArray: any 阅读全文
摘要:
手写apply /** * Function.apply(this: Function, thisArg: any, argArray?: any): any * @param {*} context */ Function.prototype._apply = function(context){ 阅读全文
摘要:
手写call /** * 实现call * @param {*} context * fn.call(target,...args) * 让fn中的this指向target * 思路是函数默认指向调用者,在目标对象上挂载fn,执行的时候fn中的this默认指向目标对象, 执行完拿到结果并删除这个挂载 阅读全文
摘要:
实现reduce /** * * @param {*} cb callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any): any * @param {*} thisA 阅读全文
摘要:
实现filter /** * 实现filter * @param {*} cb cb : (predicate: (value: any, index: number, array: any[]) => value is S, thisArg?: any): S[] * @param {*} thi 阅读全文
摘要:
手写foreach /** * forEach(cb,thisArg) * cb : (value: any, index: number, array: any[]) => void, thisArg?: any): void * 接受第二个参数thisArg,只是定制forEach中this的指 阅读全文