weixin_39774808 2020-11-21 22:05
浏览 0

Suggestion: Real local variables

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

  • 写回答

2条回答 默认 最新

  • weixin_39774808 2020-11-21 22:06
    关注

    You don't need to create a variable at the top because all the variables had declared in toolbox.They can choose local/global at that time.

    评论

报告相同问题?