我在單個.js
文件上有2 functions
。當其他功能調用時,功能無法控制檯日誌記錄
function notUsed(id) {
//default to false because if true then id not being used and good for new user
var notInUse = false;
console.log(notInUse);
return !notInUse;
}
function generateID() {
//number of zeros represents the number of digits in id code
const SIZEOFID = 10000000;
const ID_DIGITS = 7;
//letter to start id for non los rios people
const STRTOFID = "C";
//variable to hold finished id code & variable to hold 7 digit of id code
var id, idNum;
//loop to make sure id contains 7 digits and 1 letter and not used already
do {
idNum = Math.round(Math.random() * SIZEOFID);
idNum.toString();
id = (STRTOFID + idNum);
}while(id.length != (ID_DIGITS+1) && notUsed(id));
console.log(id);
}
當我打電話從我的網頁generateID()
,在ID
得到記錄,但false
不得到記錄(顯然NOTUSED功能不全)。但是,如果我將每個function
與我的網頁分開呼叫,則會登錄ID
和false
。我該如何修復或解決此問題?任何評論幫助。
它對我有效 –
@Dij獲取日誌的ID只是一個隨機ID,帶有單個字符和7位 –
@MarcoSalerno從網頁上的腳本標記中調用generateID()時? –