jscript if for global variable
Here's my code
var isNew = true
function limb(a,b)
{
if (isNew=true)
{
post(a,b);
isNew = false;
post ("first");
}
else
{
post(a,b);
post ("not first");
}
}
开发者_StackOverflow中文版
The problem I'm having is that else condition is never triggered. I'm assuming value of isNew is never updated, but I have no idea why.
You should use if (isNew===true) to test it.
In some languages = is used both to assign values and to compare them. JavaScript uses different operators for each of these.
x = 10 always means "set x to 10, and give me the value of x".
x == 10 always means "tell me if x is equal to 10".
So your condition could have been if(isNew == true) and it would have worked. You can also just put if(isNew).
加载中,请稍侯......
精彩评论