第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

javascript 函數(shù)取得調(diào)用對(duì)象的信息。

javascript 函數(shù)取得調(diào)用對(duì)象的信息。

繁星淼淼 2018-09-13 14:09:20
function testObject(){            this.commonFun=function() {                console.log(arguments.callee.caller);             }         }         (function () {            function test1() {                this.test = "test1";                         this.testFun = function () {                     (new testObject()).commonFun();                 }             }            var test1 = new test1();             test1.testFun();         }());         (function () {            function test2() {                this.test = "test2";                         this.testFun = function () {                     (new testObject()).commonFun();                 }             }            var test2 = new test2();             test2.testFun();         }());上面的console.log() 打印的調(diào)用函數(shù),但我現(xiàn)在想要的是調(diào)用對(duì)象的信息,如,test1對(duì)象調(diào)用的返回的是test1的test屬性,就是輸出 test1,test2對(duì)象調(diào)用的返回的是test2的test屬性,就是輸出 test2函數(shù)commonFun作用是輸出調(diào)用對(duì)象的的某些屬性,就像上面的test屬性,不能傳入?yún)?shù)
查看完整描述

1 回答

?
Qyouu

TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超11個(gè)贊

function testObject(){                                                              
  console.log('is testObject');                                                     
  this.commonFun=function() {                                                       
    console.log(arguments.callee.caller);                                           
  }                                                                                 
}

commonFun的caller就一直是testObject,你這種調(diào)用方法,做不到通過(guò)caller來(lái)顯示更上一層的調(diào)用關(guān)系。

可以改寫(xiě)成:

function testObject(){                                                              
  console.log('is testObject');                                                     
  this.commonFun=function(arg1) {                                                       
    console.log(arguments.callee.caller);    console.log(arg1);
  }                                                                                 
}

(function () {                                                                      
                                                                                    
  function test1() {                                                                
    this.test = "test1";                                                                                                                                    
    this.testFun = function () {                                                    
      (new testObject()).commonFun(this.test);                                               
    }                                                                               
  }                                                                                 
                                                                                    
  var test1 = new test1();                                                          
  test1.testFun();                                                                  
                                                                                    
}())


查看完整回答
反對(duì) 回復(fù) 2018-10-18
  • 1 回答
  • 0 關(guān)注
  • 563 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)