在https://github.com/Khan/khan-exercises/blob/master/khan-exercise.js两个同名变量
有两个var Khan
变量。怎么来的?他们互相影响?
在https://github.com/Khan/khan-exercises/blob/master/khan-exercise.js两个同名变量
有两个var Khan
变量。怎么来的?他们互相影响?
变量包裹在匿名函数只有在该函数内部工作。
所以这应该工作正常。
<script type="text/javascript">
$(function(){
var khan = (function(){
var khan = //this should not be a problem and they both work, this will be only available in the function
});
});
</script>
这会是很好,如果你添加的相关部分 –
给的代码进行快速检查的摘录,在我看来,汗命名函数(VAR卡恩的第一个声明)包含一个名为汗的对象.. 。我不认为这有冲突,因为他们在不同的范围 –