-
No hay comentarios, léalo usted mismo, muévase a Dachang si lo domina.
-
Escribir a mano un nuevo :
function _new(fn, ...args) { const obj = Object.create(fn.prototype) const ret = fn.apply(obj, args) return ret instanceof Object ? ret : obj }
-
Escribe una llamada a mano :
Function.prototype._call = function (context, ...args) { let context = context || window context.fn = this const res = context.fn(...args) delete context.fn return res }
-
Escriba una solicitud a mano :
Function.prototype._apply = function (context, arr) { let context = context || window context.fn = this let res if (!arr) { res = context.fn() } else { res = context.fn(...arr) } delete context.fn return res }
-
Escribe un enlace a mano :
Function.prototype._bind = function (context, ...args) { let self = this return function (...rest) { return self.apply(context, [...rest, ...args]) } }
-
Escribir a mano una instancia de:
function _instanceof(left, right) { let right = right.prototype let left = left.__proto__ while(true){ if (left === null) { return false } if (left === right) { return true } left = left.__proto__ } }
-
Escribe una reducción a mano :
Array.prototype._reduce = function(fn, value) { const arr = this let acc = value || array[0] const startIndex = value ? 0 : 1 for (let i = startIndex; i<arr.length; i++) { acc = fn(acc, arr[i], i, arr) } return acc }
Una serie de escritura a mano de Xiaofeng 1 (nuevo / llamar / aplicar / vincular / instancia de / reducir)
Supongo que te gusta
Origin blog.csdn.net/weixin_38653273/article/details/115263696
Recomendado
Clasificación