[英]Calling a function with the same name as a local variable
I have the following code... 我有以下代码...
var firstPlay = 1;
if (firstPlay == 1) {
firstPlay();
}
When I remove the if statement and just put 当我删除if语句并放
firstPlay();
Then it works but with the if statement it doesn't. 然后它可以工作,但是使用if语句则不行。
Did I make a typo? 我打错字了吗? If not how can I go about debugging this problem? 如果没有,我该如何调试该问题?
You are setting the variable firstPlay
to the value 1, you can't run a value... use different names for your variables. 您正在将变量firstPlay
设置为值1,无法运行值...为变量使用不同的名称。
Such as: 如:
var firstPlayTest = 1;
if (firstPlayTest == 1) { firstPlay(); }
A previous function definition of function firstPlay() is replaced/redefined by the numerical value 1. In the following code 函数firstPlay()的先前函数定义由数值1代替/重新定义。在以下代码中
function firstPlay() {alert("firstPlay");}
alert(firstPlay);
var firstPlay = 1;
alert(firstPlay);
the first alert shows a function definition while the second alert shows "1". 第一个警报显示功能定义,而第二个警报显示“ 1”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.