Why is arguments.callee.caller.name undefined?

后端 未结 4 1432
猫巷女王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:33

    If you do this:

    var foo = {
        sendRequest: function() {
            alert(bar.getUrl());
        }
    };                    
    
    var bar = {
        getUrl: function() {
            return  arguments.callee;
        }
    };
    
    foo.sendRequest();
    

    You will notice that the function doesn't have name which is true:

    function() {
    

    This is anonymous function.

    You can name you method : sendRequest: function myMethodName() {

提交回复
热议问题