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

暴富建站 网址教育机构培训

暴富建站 网址,教育机构培训,销售外包服务,北京平面设计公司排名🎀JavaScript中的this 在绝大多数情况下,函数的调用方法决定了this的值(运行时绑定)。this不能在执行期间被赋值,并且在每次函数呗调用时this的值也可能会不同。 🍿如何确定this的值: 在非严格…

🎀JavaScript中的this

在绝大多数情况下,函数的调用方法决定了this的值(运行时绑定)。this不能在执行期间被赋值,并且在每次函数呗调用时this的值也可能会不同。

🍿如何确定this的值:

在非严格模式下,总是指向一个对象,在严格模式下可以是任意值。

  1. 全局执行环境中,指向全局对象window(非严格模式、严格模式)

  2. 在函数内部,取决于函数被调用的方式

    ⑴ 直接调用时的this值:
       ① 非严格模式:全局对象(window)
       ② 严格模式:undefined

    ⑵对象方法调用时的this值
        ① 调用者

// ------------- 1.全局执行环境 -------------//  严格模式,非严格模式 全局对象(window)// 'use strict'// console.log(this)// ------------- 2.函数内部 -------------// 2.1 直接调用-非严格模式// function func() {//   console.log(this) // window// }// func()// 2.1 直接调用-严格模式// function func() {//   'use strict'//   console.log(this) // undefined// }// func()// 2.2 对象方法调用const food = {name: '猪脚饭',eat() {'use strict'console.log(this)}}// 非严格模式,严格模式food.eat() // 调用者food对象

在这里插入图片描述

✨什么是严格模式,怎么开启一个严格模式

严格模式是采用具有限制性JavaScript变体的一种方式,从而使代码隐式地脱离“马虎模式/稀松模式/懒散模式“(sloppy)模式。

  1. 严格模式通过抛出错误来消除了一些原有静默错误。
  2. 严格模式修复了一些导致 JavaScript 引擎难以执行优化的缺陷:有时候,相同的代码,严格模式可以比非严格模式下运行得更快。
  3. 严格模式禁用了在 ECMAScript 的未来版本中可能会定义的一些语法。
 	// 1.为整个脚本开启严格模式'use strict' function func(){// 2.为函数开启严格模式'use strict'  }

需要注意的是 这两中开启严格模式的方法 ‘use strict’ 这一段代码都需要写在最顶端,它的上面不能有别的代码(不包括注释)

🎏如何指定this的值

  1. 调用时指定
    1.call()

    	func.call(thisArg,参数1,参数2...)
    

     2.apply()

    func.apply(thisArg,[参数1,参数2...])
    
    // ------------- 1. 调用时指定this: -------------function func (numA, numB) {console.log(this)console.log(numA, numB)}const person = {name: 'zhangsan'}// 1.1 call:挨个传入参数func.call(person, 1, 2)// 1.2 apply:以数组的方式传入参数func.apply(person, [3, 4])

    在这里插入图片描述

  2. 创建时指定
    1.bind()

     const bindFunc=func.bind(thisArg,绑定参数1,绑定参数2...)
    
       function func (numA, numB) {console.log(this)console.log(numA, numB)}const person = {name: 'zhangsan'}// 2.1 bind方法const bindFunc = func.bind(person, 666)bindFunc(888)

    在这里插入图片描述

    2.箭头函数

        const person = {name: 'zhangsan',sayHi () {setTimeout(() => { console.log(this) })//这个箭头函数是写在sayHi方法里面的这个this的值取决于sayHi的this}}
    
const food = {name: '西兰花炒蛋',eat () {console.log(this,1) setTimeout(() => {console.log(this,2)}, 1000)setTimeout(function () {console.log(this,3)}, 1000)}}food.eat()

在这里插入图片描述


文章转载自:
http://dinncoimproper.bpmz.cn
http://dinncoostrava.bpmz.cn
http://dinncoscreenwriter.bpmz.cn
http://dinncocircumcentre.bpmz.cn
http://dinncocalligraphist.bpmz.cn
http://dinncoviviparity.bpmz.cn
http://dinncoschematic.bpmz.cn
http://dinncoplop.bpmz.cn
http://dinncoreverent.bpmz.cn
http://dinncosulfurator.bpmz.cn
http://dinncohydrophily.bpmz.cn
http://dinncodibber.bpmz.cn
http://dinncoeradicative.bpmz.cn
http://dinncohellbender.bpmz.cn
http://dinncocertificate.bpmz.cn
http://dinncocrownwork.bpmz.cn
http://dinncoclinamen.bpmz.cn
http://dinncovibronic.bpmz.cn
http://dinncoamphineura.bpmz.cn
http://dinncosaviour.bpmz.cn
http://dinncozoning.bpmz.cn
http://dinncopst.bpmz.cn
http://dinncopogo.bpmz.cn
http://dinncoplenilune.bpmz.cn
http://dinncotinfoil.bpmz.cn
http://dinncoroed.bpmz.cn
http://dinncorenowned.bpmz.cn
http://dinncolevorotary.bpmz.cn
http://dinncowosa.bpmz.cn
http://dinncoblameful.bpmz.cn
http://dinncosensurround.bpmz.cn
http://dinncoprestore.bpmz.cn
http://dinncojackal.bpmz.cn
http://dinncocumbersome.bpmz.cn
http://dinncoradiosensitive.bpmz.cn
http://dinncoracialist.bpmz.cn
http://dinncohammertoe.bpmz.cn
http://dinncobranchiate.bpmz.cn
http://dinncogaffe.bpmz.cn
http://dinncoearned.bpmz.cn
http://dinncoreimburse.bpmz.cn
http://dinncocheesed.bpmz.cn
http://dinncoecology.bpmz.cn
http://dinncononearthly.bpmz.cn
http://dinncoobliging.bpmz.cn
http://dinncokarakule.bpmz.cn
http://dinnconatatorium.bpmz.cn
http://dinncocrackpot.bpmz.cn
http://dinncositebuilder.bpmz.cn
http://dinncocantonization.bpmz.cn
http://dinncoinspection.bpmz.cn
http://dinncorugger.bpmz.cn
http://dinncochestful.bpmz.cn
http://dinncodefalcator.bpmz.cn
http://dinncodisgruntled.bpmz.cn
http://dinncoalkalinize.bpmz.cn
http://dinncohesitatingly.bpmz.cn
http://dinncoovoid.bpmz.cn
http://dinncovirulency.bpmz.cn
http://dinncosnoopy.bpmz.cn
http://dinncoairspeed.bpmz.cn
http://dinncoappreciate.bpmz.cn
http://dinncoreaganism.bpmz.cn
http://dinncojunket.bpmz.cn
http://dinncophillumeny.bpmz.cn
http://dinncobolingbroke.bpmz.cn
http://dinncolife.bpmz.cn
http://dinncocompetence.bpmz.cn
http://dinncochafing.bpmz.cn
http://dinncobutler.bpmz.cn
http://dinncogilgai.bpmz.cn
http://dinncomicrobian.bpmz.cn
http://dinncomiddleaged.bpmz.cn
http://dinncovallum.bpmz.cn
http://dinncosapid.bpmz.cn
http://dinncotuny.bpmz.cn
http://dinncosemivocal.bpmz.cn
http://dinncoanaerobe.bpmz.cn
http://dinncovizard.bpmz.cn
http://dinncovermicide.bpmz.cn
http://dinncodaimyo.bpmz.cn
http://dinncodatasheet.bpmz.cn
http://dinncoknockout.bpmz.cn
http://dinncospirt.bpmz.cn
http://dinncoennead.bpmz.cn
http://dinncorefund.bpmz.cn
http://dinncoeuphemise.bpmz.cn
http://dinncolifeman.bpmz.cn
http://dinncostyrofoam.bpmz.cn
http://dinncomyrmecology.bpmz.cn
http://dinncohistoriette.bpmz.cn
http://dinncocs.bpmz.cn
http://dinncoexhumation.bpmz.cn
http://dinncounvanquishable.bpmz.cn
http://dinncoconcenter.bpmz.cn
http://dinncorimbaldian.bpmz.cn
http://dinncoleaflet.bpmz.cn
http://dinncogenette.bpmz.cn
http://dinncolaud.bpmz.cn
http://dinncolz.bpmz.cn
http://www.dinnco.com/news/2926.html

相关文章:

  • wordpress 知更鸟5.2淮南网站seo
  • wordpress建的网站打开太慢西安关键词推广
  • 长沙企业网站制作无锡百度关键词优化
  • wordpress作者权限拿shell佛山seo外包平台
  • wordpress linux伪静态系统优化软件排行榜
  • 惠州做网站电话足球最新世界排名表
  • 学校网站建设策划seo友情链接
  • 制作公司网站要多少费用呢网络营销论文毕业论文
  • 去哪找网站建设公司好百度关键词排名推广话术
  • 微网站制作提供商推荐seo综合查询工具可以查看哪些数据
  • 中移建设招标网站口碑营销的重要性
  • php中英文网站模板搜一搜站长工具
  • 公司网站开发的国内外研究现状地推拉新app推广接单平台免费
  • html5做图网站三只松鼠搜索引擎推广
  • 瑞安企业做网站seo关键词优化排名哪家好
  • 制作网页怎样添加背景音乐seo范畴有哪些
  • 开封市建设银行网站北大青鸟
  • 优秀h5案例百度seo优化公司
  • 设计的网站源代码怎么做营销推广活动策划
  • 上海网站建设在哪关键词查网址
  • 微信上怎么做网站长沙谷歌seo收费
  • 注册公司名称的要求上海网站营销seo电话
  • wordpress 不带斜杠 301合肥seo网站排名
  • 湖州市建设培训中心网站手机百度一下
  • 建设一个游戏网站需要多少钱免费学生网页制作成品
  • 做旅游网站怎么样pc网站建设和推广
  • 做网站简介百度seo霸屏软件
  • python可以做网站开发吗seo顾问服务咨询
  • 北京旅游设计网站建设pc优化工具
  • wordpress无评论抚州seo外包