【发布时间】:2016-06-20 00:28:43
【问题描述】:
在 javascript 中,我尝试在类的函数中使用 for 循环。这是我的代码:
<!DOCTYPE html>
<html>
<body>
<p>Testing</p>
<p id="thing"></p>
<script>
class test{
func(){
for (t=0; t<4; t++){ // If you comment out
} // These lines it works
}
}
var x = new test();
x.func();
var str1 = "It works!";
document.getElementById("thing").innerHTML = str1;
</script>
</body>
</html>
这给了我这个输出:
Testing
但如果我注释掉 for 循环,它会给我这个输出:
Testing
It works!
我之前在函数中使用过 for 循环,为什么我不能/如何在类函数中使用它们?
谢谢
【问题讨论】:
-
打开浏览器的开发者控制台,你就会知道原因了。
-
同意@squint,开发者应该学会使用他的工具(控制台、ide、linting)
标签: javascript for-loop