如何使用变量声明中的匿名函数将字符串赋值给变量?

时间:2011-11-08 15:09:47

标签: javascript anonymous-function

var destURL = function () {
            if (this.typeOfDash == 'edit') {
                return '../../ajax/getParams.aspx';
            }
            else {
                return 'DashCreator.aspx';
            }

}

我希望这会有效,但它只是将函数赋给变量...我希望得到返回值作为变量值...任何人?

1 个答案:

答案 0 :(得分:6)

您可以立即评估该函数以获取返回值。

var destURL = function () {
            if (this.typeOfDash == 'edit') {
                return '../../ajax/getParams.aspx';
            }
            else {
                return 'DashCreator.aspx';
            }
}()
相关问题