Why is arguments.callee.caller.name undefined?

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

    Putting a value in an object literal, as you're doing, doesn't affect the value at all.

    var foo = {
        sendRequest: ...
    

    The function value is only affected by the function expression, which doesn't contain a name.

                 ... function() {
            alert(bar.getUrl());
        }
    

    You need to include the name you want in the function expression itself [fiddle].

    var foo = {
        sendRequest: function sendRequest() {
    

提交回复
热议问题