Why is arguments.callee.caller.name undefined?

后端 未结 4 1471
猫巷女王i
猫巷女王i 2021-01-25 04:59

How come this doesn\'t alert \"http://127.0.0.1/sendRequest\"? (Available at http://jsfiddle.net/Gq8Wd/52/)

var foo = {
    sendRequest: function() {
        ale         


        
4条回答
  •  既然无缘
    2021-01-25 05:25

    Because the function that is calling the function being called is an anonymous function (and hence, has no name).

    Try:

    function sendRequest() {
        alert(bar.getUrl());
    }
    
    var foo = {
        sendRequest: sendRequest
    };                    
    
    var bar = {
        getUrl: function() {
            return 'http://127.0.0.1/' + arguments.callee.caller.name;
        }
    };
    
    foo.sendRequest();
    

提交回复
热议问题