[英]Scope of variables in JS/nodejs
.content
和noiseWords
是由字符串組成的數組。 我的目的是從content
刪除noiseWords
。 無論content
和noiseWords
不是全局變量。 我可以在word()
訪問noiseWords
嗎? 第4行正確嗎? 如果沒有,那么我如何在word()
訪問noiseWord
?
word(content){
// this function remove noiseWords from the Content
//and then return the content
noiseWords.split(/\s+/).map((w) =>
normalize(w));//line4
}
addNoiseWords(noiseWords){
//this function consists noisewords
}
我可以在word()中訪問noiseWords嗎?
沒有
第4行正確嗎? 如果沒有,我如何在word()中訪問noiseWord? 我在代碼中提到了“第4行”。
您需要將該數組作為參數傳遞給函數word()
,例如:
function word(content, noiseWords){...}
或傳遞具有這些值的對象:
function word(obj){
var {content, noiseWords} = obj;
.
.
.
}
或傳遞具有這些值的數組:
function word(array){
var [content, noiseWords] = array;
.
.
.
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.