我正在尝试编写一个简单的函数(checkCard)来检查另一个函数创建的随机卡是否已经在使用中。这是拨打电话的地点:
var uC;
// some code including creating the random card
checkCard(card, pCards, dCards, uC);
// uC becomes unidentified here
这是支票卡本身:
function checkCard(card, pCards, dCards, uC) {
var tCards = pCards.concat(dCards), // an array containing all cards which are in use already
i;
for (i = 0; i < tCards.length; i = i + 1) {
if (card.suit === tCards[i].suit && card.type === tCards[i].type) {
uC = true; // card is in use already
break;
} else {
uC = false; // card is not in use
}
}
// it still works here: uC is either true or false
return uC;
}
}
不知何故,它不起作用:checkCard 正确计算 uC,并且在“return uC”之前保持值“true”或“false”。但是在返回到原来的函数后,uC 变得“无法识别”。我究竟做错了什么?
提前致谢!