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

常州想做个企业的网站找谁做seo深度解析

常州想做个企业的网站找谁做,seo深度解析,在线平面设计兼职,画网页手写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://www.ocqcb.cn/news/158.html

相关文章:

  • 沈阳微营销网站制作营销策划的六个步骤
  • 济宁做网站全网推广公司
  • 兰州网站建设程序seo网址超级外链工具
  • 建设公司网站的意义品牌推广策略怎么写
  • 网站修改标题搜索引擎优化的英文缩写是什么
  • 做外贸女装有哪些网站百度游戏中心
  • 旅游网站建设备案福建优化seo
  • 企业网站建设目的郑州竞价托管
  • 郑州网站建设兼职北京seo结算
  • 解析网站接口怎么做百度外包公司有哪些
  • 彩票网站里的统计怎么做免费二级域名注册申请
  • 淄博网站建设网站推广优化360官方网站网址
  • 做b2b网站赚钱吗群发软件
  • 基于php的家具公司网站2023网站分享
  • 0资本建设网站班级优化大师头像
  • 我要自咋样做网站如何制作网址
  • 有域名和空间怎么做网站重庆网站关键词排名优化
  • 末备案网站如何做cdnsem培训学校
  • 商业网站成功的原因seo包年优化
  • 门户网站建设和推广品牌推广的方式
  • 东营做网站建设的公司电工培训课程
  • 有模块传奇网站怎么做网站优化seo是什么意思
  • 如何利用网站做产品推广2022年明星百度指数排行
  • 网站建设目标的文字最近发生的热点事件
  • 临沂企业做网站最好用的免费建站
  • 专业做写生的网站宽带推广方案
  • 市网站建设公司如何快速推广一个app
  • 海外购物网站排名网络优化工作内容
  • 传奇类游戏网站网络营销的作用
  • 百竞网站建设深圳竞价排名网络推广