zoukankan      html  css  js  c++  java
  • call、apply

    手写call方法

      Function.prototype.call = function(content){

        content = content ? Object(content) : window;

        content.fn = this;

        let args = [ ];

        for(var i = 1; i < arguments.length; i ++){

          args.push(arguments[i])

        }

        let res = content.fn(...args);

        delete content.fn;

        return res;

      }

    手写apply方法

      Function.prototype.apply = function(context, args) {

        context = context ? Object(context) : window;

        context.fn = this;

        if (!args) {

          return context.fn();

        }

        let res = context.fn(...args);

        delete context.fn;

        return res;

      }

  • 相关阅读:
    freopen
    字符
    map映射
    P3512 [POI2010]PIL-Pilots-洛谷luogu
    快读
    单调队列&单调栈
    简写
    邻接表&链式前向星
    mysql参数详解
    网络管理指南
  • 原文地址:https://www.cnblogs.com/cuishuangshuang/p/13433606.html
Copyright © 2011-2022 走看看