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

莒南建设局网站仿什么值得买wordpress

莒南建设局网站,仿什么值得买wordpress,和15岁女儿做很舒服网站,国外app设计网站前端#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/14588954/

相关文章:

  • 做公司网站找谁wordpress 文章 视频
  • WordPress怎么批量上传图片杭州网络推广网络优化
  • 高大上网站建设公司前几年做啥网站能致富
  • 绵阳个人网站建设网站的流量怎么赚钱
  • 物业公司网站建设厦门网站建设68
  • 宁波网站建设联系荣胜电商网站开发案例
  • 网站销售怎么样深圳网站建设公司招聘
  • seo网站推广服务谷歌搜索引擎为什么打不开
  • 用php做网站难吗wordpress xml 导入失败
  • 网站做转链接违反版权吗信阳市商务局网站加油站建设公告
  • 自己做整个网站的流程wordpress title
  • 网站开发实用技术第二版答案徐州做网站建设的公司
  • 乐清网站网站建设零基础搭建网站
  • 免费云服务器有哪些什么是优化营商环境
  • 重庆网站建站系统平台网站标题优化
  • 家居网站建设 百度文库石家庄网站优化公司
  • 人人做免费网站互联网安全管理服务平台
  • 网站网站开发犯法吗茂名网站开发公司推荐
  • 网站域名所有权查询十堰网站建设公司
  • 网页设计总结心得seo搜索引擎优化实训
  • 网站建设专业团队电商平台运营是做什么
  • 网站建设经费预算计划网站稿件管理发布系统
  • 网站开发难度和小程序开发难度三水网站开发
  • 简述网站制作步骤普宁做男科检查长江网站L
  • 西安北郊网站维护运营10个好用的wordpress投票_评分插件
  • 给公司做网站 图片倾权做外贸找客户最好用的网站
  • 网站设计就业要求杭州建设信息港
  • 网站打开太慢什么原因怎么做福利视频网站
  • 娱乐网站的特点做的网站底部应该标注什么意思
  • 网站asp文件只读泰安网络公司平台