日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ES5-13 对象属性遍历、this、callee、caller

發(fā)布時間:2023/12/10 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ES5-13 对象属性遍历、this、callee、caller 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

鏈?zhǔn)秸{(diào)用

  • 在每個函數(shù)內(nèi)部return this

訪問對象屬性

  • 點(diǎn)語法
  • []中括號內(nèi)是字符串或是變量
  • 數(shù)組是特殊的對象

    對象屬性遍歷

    • for in(遍歷對象或數(shù)組) - 不必再用Object.keys那么麻煩了
    for(var key in obj){console.log(obj[key])// obj.key返回undefined// 因為js引擎會轉(zhuǎn)換為obj['key'] }
    • instanceof
    console.log([] instanceof Array) // true console.log([] instanceof Object) // true console.log({} instanceof Object) // true
    • 類型判斷
    var a = [] || {} console.log(a.constructor) console.log(a instanceof Array) console.log(Object.prototype.toString.call(a)) // 實際運(yùn)用時先緩存 var strFn = Object.prototype.toString// Object.prototype = { // toString:function(){ // this.toString() // this → a // } // }


    函數(shù)內(nèi)部的this

    • 只要沒有實例化構(gòu)造函數(shù),函數(shù)內(nèi)部的this指向window
    • 全局范圍的this指向window
    • 構(gòu)造函數(shù)內(nèi)this指向

    arguments.callee - 正在被執(zhí)行的函數(shù)對象

    function test(a, b, c, d) {console.log(arguments.callee.length) } test() // 4
    • 應(yīng)用,在自啟動函數(shù)中使用遞歸,且不需要函數(shù)名
    var res = (function (n) {if (n <= 1) {return 1}return n = n + arguments.callee(n - 1) })(10); console.log(res) // 55

    caller - 當(dāng)前函數(shù)的調(diào)用者

    • 嚴(yán)格模式下,使用arguments、callee、caller會報錯
    dad() function dad() {child() } function child() {console.log('child的調(diào)用者', child.caller) }

    練習(xí)

    • typeof的返回值有幾種:6種
    • 如何不用isNaN判斷NaN(轉(zhuǎn)換成字符串)

    • 引用值對比的是地址(這個是比較,不是隱式類型轉(zhuǎn)換)


    • 函數(shù)test的AO有a

    apply、call傳null,this指向是什么

    function Test(name) {this.name = name } function Test2() {Test.call(null, '測試') } console.log('obj', new Test2())

    總結(jié)

    以上是生活随笔為你收集整理的ES5-13 对象属性遍历、this、callee、caller的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。