奶头挺立呻吟高潮av全片,成人试看120秒体验区,性欧美极品v,A片高潮抽搐揉捏奶头视频

JavaScript

JavaScript中this的用法步驟

時(shí)間:2024-06-19 02:10:01 JavaScript 我要投稿
  • 相關(guān)推薦

JavaScript中this的用法步驟

  關(guān)于JavaScript中this的用法網(wǎng)絡(luò)中已經(jīng)有較多比較詳盡的介紹,可以參考本文的參考學(xué)習(xí)資料和網(wǎng)絡(luò)。本文結(jié)合網(wǎng)絡(luò)收集整理,嘗試以一種簡(jiǎn)易的方式闡述JavaScript中this的用法,希望對(duì)大家關(guān)于JavaScript中this用法的快速理解有所幫助。

  1. this用法實(shí)例

  復(fù)制代碼 代碼如下:

  window.color = “red”;

  var o = { color: “blue” };

  function sayColor(){

  alert(this.color);

  }

  sayColor(); //”red”

  o.sayColor = sayColor;

  o.sayColor(); //”blue”

  2. this用法簡(jiǎn)易理解

  this指向哪里:

  this運(yùn)行的環(huán)境(the context object),或者簡(jiǎn)單理解為:this所在函數(shù)被調(diào)用時(shí)的當(dāng)前作用域。

  一段實(shí)例代碼立刻明白:

  復(fù)制代碼 代碼如下:

  var fun = function() {

  console.log(this);

  }

  fun();// console: window,fun 的執(zhí)行context為window,即this所在函數(shù)(fun())被調(diào)用時(shí)的當(dāng)前作用域?yàn)閣indow。

  new fun();//console: fun,fun 的執(zhí)行context為fun對(duì)象內(nèi),即this所在函數(shù)(fun())被調(diào)用時(shí)的當(dāng)前作用域?yàn)閒un對(duì)象內(nèi)。

  3. this用法的一個(gè)特殊情況

  (1)情況:

  復(fù)制代碼 代碼如下:

  function demo() {

  this.value = Math.random();

  }

  點(diǎn)擊這個(gè)button之后,你會(huì)發(fā)現(xiàn)按鈕的value值沒(méi)有改變。

  原因:在本代碼運(yùn)行的情況下this指向的是window對(duì)象。

  復(fù)制代碼 代碼如下:

  var button = document.getElementById("aButton");

  function demo() {

  this.value = Math.random();

  }

  button.onclick= demo;

  點(diǎn)擊這個(gè)button之后,程序可正常執(zhí)行。

  (2)原因解釋?zhuān)?/p>

  復(fù)制代碼 代碼如下:

  var button = document.getElementById("aButton");

  function demo() {

  this.value = Math.random();

  }

  button.onclick= demo;

  alert(button.onclick);

  得到的輸出是:

  復(fù)制代碼 代碼如下:

  function demo() {

  this.value = Math.random();

  }

  復(fù)制代碼 代碼如下:

  var button = document.getElementById("aButton");

  function demo() {

  this.value = Math.random();

  }

  alert(button.onclick);

  得到的輸出是:

  復(fù)制代碼 代碼如下:

  function onclick() {

  demo();

  }

【JavaScript中this的用法步驟】相關(guān)文章:

在word中畫(huà)圖的步驟04-22

如何調(diào)試javascript腳本呢07-19

javascript跨域訪(fǎng)問(wèn)的方法07-19

all用法要點(diǎn)07-24

again用法詳解08-25

英語(yǔ)祈使句的結(jié)構(gòu)及用法06-17

英語(yǔ)介詞to的用法匯總02-01

2018中考必考文言文虛詞18個(gè)及用法說(shuō)明02-13

英語(yǔ)方位名詞的用法07-19

俄語(yǔ)動(dòng)詞“體”的用法02-04

主站蜘蛛池模板: 隆德县| 康马县| 元氏县| 固阳县| 托克托县| 湘乡市| 峨山| 正蓝旗| 汉沽区| 平定县| 内丘县| 扬中市| 曲阜市| 衡阳县| 衢州市| 江都市| 图们市| 兰西县| 廊坊市| 金秀| 葵青区| 玛多县| 汉源县| 桐梓县| 万州区| 益阳市| 衡阳县| 平顺县| 思南县| 庐江县| 定州市| 恩平市| 上杭县| 克什克腾旗| 平泉县| 广元市| 磐安县| 遵义县| 张家口市| 华容县| 白山市|