本文介绍了为什么arguments.callee.caller.name 未定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这怎么不提醒http://127.0.0.1/sendRequest"?(可在 http://jsfiddle.net/Gq8Wd/52/ 获得)

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

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

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

foo.sendRequest();

推荐答案

将值放入对象字面量中,正如您所做的那样,根本不会影响该值.

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 .

var foo = {
    sendRequest: function sendRequest() {

这篇关于为什么arguments.callee.caller.name 未定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 16:31