There are few kinds of local variable: 1) sprite-scope, Like scratch2.0 2) block(group)-scope, or rootblock-scope, like closure-scope
(function () {
var a = 1;
})()
3) statement-scope, strict local variable, like
if {
let a = 1;
} else {
let a = 2;
}
I think (2) is better, that makes local variable in each recursion available and more convenient than strict local variable.
function search(depth, s) {
if (depth > 3) {
//do something
return;
}
for (var i = 0; i < 10; ++i) {
search(depth + 1, i);
}
}
该提问来源于开源项目:LLK/scratch-vm