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

仿什么值得买wordpress大连网站优化技术

仿什么值得买wordpress,大连网站优化技术,好的网站域名,网站底部模板前端#xff1a;JavaScript中的this 1. this的指向2. 指定this的值3. 手写call方法4. 手写apply方法5. 手写bind方法 1. this的指向 在非严格模式下#xff0c;总是指向一个对象#xff1b;在严格模式下可以是任意值。 开启严格模式#xff0c;如果是为整个脚本开启#… 前端JavaScript中的this 1. this的指向2. 指定this的值3. 手写call方法4. 手写apply方法5. 手写bind方法 1. this的指向 在非严格模式下总是指向一个对象在严格模式下可以是任意值。 开启严格模式如果是为整个脚本开启直接在当前脚本第一行代码写上如下代码 use strict如果是为函数开启严格模式则是在函数第一行写上上述代码 function a(){use strict }全局执行环境中指向全局对象即window严格、非严格模式函数内部取决于函数被调用的方式。如果直接调用this严格模式下为undefined非严格模式下为全局对象(window)如果采用对象方法调用的this 则指向调用者(严格、非严格) 直接调用 function a(){console.log(this);}function b() {use strictconsole.log(this);}a() // windowb() // undefined对象方法调用 const food {name:西瓜,dec(){console.log(this)} } const food2 {name: 香蕉,dec() {use strictconsole.log(this)} } food.dec() // food这个对象 food2.dec() // food2这个对象2. 指定this的值 调用时指定call、apply(数组传递参数)创建时指定bind箭头函数 call使用如下 func.call(thisArg,参数1参数2...)function func(num1,num2){console.log(this);console.log(num1,num2);}const person {name:baidu}func.call(person,1,2)apply使用如下 func.apply(thisArg,[参数1参数2...])function func(num1,num2){console.log(this);console.log(num1,num2);}const person {name:baidu}func.apply(person,[2,3])bind使用如下 func.bind(thisArg,绑定参数1绑定参数2...)function func(num1,num2){console.log(this);console.log(num1,num2);}const person {name:baidu}const bindFunc func.bind(person,77)bindFunc(88)箭头函数 使用普通函数此时最里层的this指向window const person {name:baidu,hh(){console.log(this);setTimeout(function(){console.log(this);},1000)}}person.hh()使用箭头函数最里层的this指向其外层的this值。 const person {name:baidu,hh(){console.log(this);setTimeout((){console.log(this);},1000)}}person.hh()3. 手写call方法 任何定义的函数都是属于Function类型那么只需要在Function其原型上添加一个call方法其他自定义的函数上均可以使用call方法这里定义的call方法名为myCall。 Function.prototype.myCall function(thisArg,...args){thisArg.f this// this指向调用myCall的那个函数const res thisArg.f(...args)// 传递进来的args参数为数组类型delete thisArg.freturn res }但是上述还存在一个问题那就是如果thisArgs这个对象上也刚好存在f属性上述操作会把原对象thisArgs的f属性去掉。因此可以考虑使用SymbolSymbol无论调用多少次其返回值均是唯一的。 function func(num1, num2) {console.log(this);console.log(num1, num2);}const person {name: baidu}Function.prototype.myCall function(thisArg,...args){const key Symbol(key);thisArg[key] this// this指向调用myCall的那个函数const res thisArg[key](...args)delete thisArg[key]return res}func.myCall(person,22,33)运行结果 4. 手写apply方法 和myCall类似只是传递参数不同而已。 function func(num1, num2) {console.log(this);console.log(num1, num2); } const person {name: baidu } Function.prototype.myApply function(thisArgs,args){const key Symbol(key)thisArgs[key] thisconst res thisArgs[key](...args)delete thisArgs[key]return res } func.myApply(person,[44,66])5. 手写bind方法 function func(num1, num2) {console.log(this);console.log(num1, num2); } const person {name: baidu } Function.prototype.myBind function(thisArgs,...args){return (...newArgs){return this.call(thisArgs,...args,...newArgs)} } const myBindFunc func.myBind(person,1) myBindFunc(2)箭头函数中this指向func即其调用者(外层this的指向)
http://www.hkea.cn/news/14502110/

相关文章:

  • 网站什么时候做等保网站建设大作业选题
  • 营销型企业网站推广的方法有哪些装修风格大全2021新款简约
  • 云阿里云做网站网页设计与制作教程书
  • 聊天网站备案wordpress优惠券发放插件
  • 织梦建站教程全集如何做枪版电影网站
  • 做网站数据库要建什么表如何查看网站ftp地址
  • 哈尔滨建设网官方网站wordpress 发邮件 慢
  • 锦州建设局网站企业建一个网站需要多少钱
  • 做国外电影网站广州化妆品网站设计
  • 怎么用安卓机顶盒做网站服务器泰安手机网站
  • 校园微网站建设方案ppt花都个性设计商城网站建设
  • 苏州知名网站制作开发做网站公司 陕西渭南
  • 自己做网站微商电脑做视频的网站比较好
  • 北京网站设计公司哪个好wordpress 订阅者
  • 网站域名年龄查询成都住建局官网官网官方
  • 济南网站建设公司哪个好如何在网上注册公司网站
  • 网站美工外包公司公司网站被百度转码了
  • 安徽住房与城乡建设厅网站免费货源在线永久
  • 长治网站制作怎么做做网站需求方案
  • 网站推广方案注意事项国外饮品网站
  • 免费站推广网站2022怎么用ftp清空网站
  • 网站右侧信息跟随左侧菜单栏变化电影手机网站建设
  • 石家庄招聘哪个网站做的好平台设计标准
  • 帝国做的网站删除域名后缀海南免费做网站
  • 微信营销软件网站建设优秀网站建设哪家专业
  • 做网站备案成功后怎么办知东莞app下载
  • 一建 建设网站wordpress主题the7中文汉化版
  • 网络优化网站 site网页设计版权信息代码
  • 什么是工具型网站商业网站建设的目的
  • 东莞微信网站开发洛阳洛龙区网络营销公司