call是为了借用自己没有但是别人有的方法而设计的.
const arrayLike = {a: 123,b: 456}Function.prototype.myCall = function ( ctx, params) {if (ctx === null || ctx === undefined) {ctx = window} else {ctx = Object(ctx)}const symbol = Symbol('functionName') // 用symbol可以避免变量名冲突ctx[symbol] = thisconst result = ctx[symbol](params)delete ctx[symbol]return result}Array.prototype.push.myCall(arrayLike, 789)console.log(arrayLike)
