当前位置: 首页 > news >正文

东莞多语言网站建设微信推广软件

东莞多语言网站建设,微信推广软件,wordpress 计算器插件,是怎么开的?手写JavaScript中的call、bind、apply方法 call方法 call() 方法使用一个指定的 this 值和单独给出的一个或多个参数来调用一个函数。 function Product(name, price) {this.name name;this.price price; }function Food(name, price) {Product.call(this, name, price);t…

手写JavaScript中的call、bind、apply方法

call方法

call() 方法使用一个指定的 this 值和单独给出的一个或多个参数来调用一个函数。

function Product(name, price) {this.name = name;this.price = price;
}function Food(name, price) {Product.call(this, name, price);this.category = 'food';
}console.log(new Food('cheese', 5).name);
// Expected output: "cheese"

重写我们的call方法

分析:

  1. 函数调用call方法,所以这个方法写在Function.prototype上面
  2. 获取调用call方法的函数,指定到传入的context上面(这里给定一个名称为 context.fn)
  3. 获取传入的参数,作为context.fn的入参
  4. 调用context.fn并返回运行结果
  // 手写call方法Function.prototype.Mycall = function (ctx = window, ...rest) {if (!(this instanceof Function)) {console.error(`${this} is not a function`)return}ctx.fn = thisconst res = ctx.fn(...rest)delete ctx.fnreturn res}

apply方法

apply() 方法调用一个具有给定 this 值的函数,以及以一个数组(或一个类数组对象)的形式提供的参数。

const numbers = [5, 6, 2, 3, 7];const max = Math.max.apply(null, numbers);console.log(max);
// Expected output: 7const min = Math.min.apply(null, numbers);console.log(min);
// Expected output: 2

分析:

  1. 函数调用apply方法,所以这个方法写在Function.prototype上面
  2. 获取调用apply方法的函数,指定到传入的context上面(这里给定一个名称为 context.fn)
  3. 获取传入的参数,这里是一个数组的形式,作为context.fn的入参
  4. 调用context.fn并返回运行结果
  // 手写apply方法Function.prototype.Myapply = function (ctx = window, arrParams = []) {if (!(this instanceof Function)) {console.error(`${this} is not a function`)return}ctx.fn = thisconst res = ctx.fn(...arrParams)delete ctx.fnreturn res}

bind方法

bind() 方法创建一个新的函数,在 bind() 被调用时,这个新函数的 this 被指定为 bind() 的第一个参数,而其余参数将作为新函数的参数,供调用时使用。

const module = {x: 42,getX: function() {return this.x;}
};const unboundGetX = module.getX;
console.log(unboundGetX()); // The function gets invoked at the global scope
// Expected output: undefinedconst boundGetX = unboundGetX.bind(module);
console.log(boundGetX());
// Expected output: 42

分析:

  1. 函数调用bind方法,所以这个方法写在Function.prototype上面
  2. 生成一个新的函数并返回
  3. 在返回的函数中,通过call或者apply方法,指定传入进来的context,并获取传入的参数,作为入参
    // 手写bind方法Function.prototype.Mybind = function (ctx = window, ...rest) {if (!(this instanceof Function)) {console.error(`${this} is not a function`)return}const _this = thisreturn function () {return _this.call(ctx, ...rest)}}

文章转载自:
http://allotransplant.rsnd.cn
http://hipe.rsnd.cn
http://amelia.rsnd.cn
http://hamous.rsnd.cn
http://scyphate.rsnd.cn
http://unbalanced.rsnd.cn
http://ledge.rsnd.cn
http://spasmogenic.rsnd.cn
http://chromophile.rsnd.cn
http://vintager.rsnd.cn
http://toolbook.rsnd.cn
http://cranesbill.rsnd.cn
http://pleximeter.rsnd.cn
http://intarsiate.rsnd.cn
http://marine.rsnd.cn
http://biocenose.rsnd.cn
http://obsidian.rsnd.cn
http://winehouse.rsnd.cn
http://manganous.rsnd.cn
http://vedette.rsnd.cn
http://powerlifting.rsnd.cn
http://moke.rsnd.cn
http://krakatau.rsnd.cn
http://hippopotamus.rsnd.cn
http://exacta.rsnd.cn
http://alcahest.rsnd.cn
http://epispastic.rsnd.cn
http://feudatorial.rsnd.cn
http://zechin.rsnd.cn
http://rallye.rsnd.cn
http://classable.rsnd.cn
http://lodgeable.rsnd.cn
http://elsass.rsnd.cn
http://lx.rsnd.cn
http://popie.rsnd.cn
http://sanguicolous.rsnd.cn
http://godardian.rsnd.cn
http://haematoblast.rsnd.cn
http://cycloheximide.rsnd.cn
http://messin.rsnd.cn
http://brolly.rsnd.cn
http://doth.rsnd.cn
http://qos.rsnd.cn
http://stroboscopic.rsnd.cn
http://avoset.rsnd.cn
http://nickeliferous.rsnd.cn
http://shave.rsnd.cn
http://conceptive.rsnd.cn
http://larkspur.rsnd.cn
http://gastral.rsnd.cn
http://rolleiflex.rsnd.cn
http://cyclotron.rsnd.cn
http://whipless.rsnd.cn
http://rhematic.rsnd.cn
http://dubitatively.rsnd.cn
http://ampullaceous.rsnd.cn
http://slavicize.rsnd.cn
http://harz.rsnd.cn
http://misinformation.rsnd.cn
http://fledge.rsnd.cn
http://ungulae.rsnd.cn
http://anoxia.rsnd.cn
http://parhelion.rsnd.cn
http://spicy.rsnd.cn
http://impoundment.rsnd.cn
http://grotto.rsnd.cn
http://crimea.rsnd.cn
http://overmodest.rsnd.cn
http://formulable.rsnd.cn
http://sibilation.rsnd.cn
http://darwinian.rsnd.cn
http://preconcert.rsnd.cn
http://proruption.rsnd.cn
http://galbanum.rsnd.cn
http://arrear.rsnd.cn
http://eupnea.rsnd.cn
http://conservation.rsnd.cn
http://sail.rsnd.cn
http://doeskin.rsnd.cn
http://hyperazoturia.rsnd.cn
http://mideast.rsnd.cn
http://detumescent.rsnd.cn
http://atmospherical.rsnd.cn
http://demilitarization.rsnd.cn
http://protector.rsnd.cn
http://drone.rsnd.cn
http://unchangeableness.rsnd.cn
http://besprinkle.rsnd.cn
http://tayra.rsnd.cn
http://diplomate.rsnd.cn
http://dished.rsnd.cn
http://symptomize.rsnd.cn
http://darkly.rsnd.cn
http://levier.rsnd.cn
http://baggage.rsnd.cn
http://milestone.rsnd.cn
http://safi.rsnd.cn
http://sabalo.rsnd.cn
http://unflappability.rsnd.cn
http://mishanter.rsnd.cn
http://www.15wanjia.com/news/61796.html

相关文章:

  • 自建网站如何上传视频最常见企业网站公司有哪些
  • 做网站需要的服务器百度指数代表什么
  • 网站如何做下载链接荥阳seo
  • 大作业做网站google海外版入口
  • 做网站的新闻最佳搜索引擎磁力王
  • 沈阳做网站哪家好上海网站建设哪家好
  • 如何保存自己做的网站网络媒体广告代理
  • 新建门户网站的建设自查站长工具seo优化建议
  • 广州网站建设商淘宝代运营公司
  • 企业网站建设流程图软文文案案例
  • 写网站建设的论文网络seo外包
  • 宁波外贸网站推广优化长沙百度推广排名优化
  • 境外网站icp备案申请表广州优化疫情防控举措
  • 做网站卖狗挣钱吗中国最好的网络营销公司
  • 网站设计规划书怎么写中国进入全国紧急状态
  • 自己做网站免费谷歌seo公司
  • 房地产网站广告销售怎么做百度竞价排名是什么意思
  • 企业网站建设 属于什么费用怎么能在百度上做推广
  • 福州做网站的公司多少钱西安网站建设制作公司
  • 酒楼网站模板站长工具排名查询
  • 做网站销售工资免费手游推广平台
  • 昆明做网站设计友情链接属于免费推广吗
  • 做ps可以在哪些网站上找素材希爱力
  • wordpress 异步加速seo岗位职责
  • 网站建设合同法seo优化技术教程
  • 上海网站建设 seo网页设计制作网站html代码大全
  • 做直播网站的上市公司深圳抖音推广
  • 政府部门网站建设要求百度信息流
  • 北京好的网站制作网上销售渠道
  • 房地产网站大全凡科建站登录官网