call是为了借用自己没有但是别人有的方法而设计的.

    1. const arrayLike = {
    2. a: 123,
    3. b: 456
    4. }
    5. Function.prototype.myCall = function ( ctx, params) {
    6. if (ctx === null || ctx === undefined) {
    7. ctx = window
    8. } else {
    9. ctx = Object(ctx)
    10. }
    11. const symbol = Symbol('functionName') // 用symbol可以避免变量名冲突
    12. ctx[symbol] = this
    13. const result = ctx[symbol](params)
    14. delete ctx[symbol]
    15. return result
    16. }
    17. Array.prototype.push.myCall(arrayLike, 789)
    18. console.log(arrayLike)