本文介绍了两个同名变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

https://github.com/Khan/khan-exercises/blob/master/khan-exercise.js

有两个 var Khan 变量.怎么来的?它们会相互影响吗?

there are two var Khan variables. How come? Do they affect each other?

推荐答案

一个Khan是全局变量Khan"的名字,另一个是里面的变量它等于的自执行函数.

One Khan is the name of the global variable "Khan", the other is a variable inside the self executing function that it is equal to.

var Khan = (function(){

    ....

    var Khan = ...

    ....

})();

源文件中的缩进太可怕了,你可能没有注意到......

The indentation in the source file is horrible and you probably did not notice that....

这篇关于两个同名变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-15 12:40