jslintkeepscomplainingaboutthingslikethis
var myarray=[ 1,2,3 ];
虚拟现实(for ) )。
{
//BLAH
}
sayingthatishouldwrapitinanifstatement.irealizeyouneedtowrapitifyouareloopingoveranobject ' sproperties,butherewhatshouldiouldies
additionallywhenidosomethinglike
for(varI=0; i 10; I )
{
//foo
}
for(varI=0; i 20; I )
{
//bar
}
itcomplainsthatihasalreadybeendefined.howdoipreventthisotherthanusingdifferentvariablenames?
jlintwhingesaboutalotthat ' snotreallyharmful.inthiscaseit ' srighttocomplainaboutfor.in,becausethat'sthewrongconstrong
thisisbecauseyouwillgetnotonlythenumerickeys,utalsoanyotherarbitrarypropertiesthavebeenaddedtothearrayoritsarray.protottay
whilstyoucandefeatthatcasewithhasownpropertytocheckit ' snotaprototypemember,it ' suglierthanjustdoingittheproperwaywithfor
Also,with for . inyouwon ' tnecessarilygettheitemsinnumericalorderasyoumightexpect。
itcomplainsthatihasalreadybeendefined.howdoipreventthisotherthanusingdifferentvariablenames?
yah,you can ignore that one。
itwantsyoutoremovethevarfromthesecondfor (I…, becausedeclaringavariabletwiceinthesamescopedoesn ' tdo anything.howeveriwouldrecommendleavingthevartherebecauseitdoesn ' tdo andifyoumovethelooptoanotherblockyoudon ' twantittobesuddenlyscribblingonglobals。