2017-08-28 46 views

回答

3

它是一个变量声明看见了。

这意味着,在短期:

var _ = this; 
var dataSettings; 
var responsiveSettings; 
var breakpoint; 

有没有价值分配仍然会在你的范围内都有效,并会使用时引发错误的变量。

参见这些3个例子之间的差别:1

实施例:

var foo; //is declared without value, aka undefined, is falsy 
if(foo){ 
    alert('This does not get called'); 
}else{ 
    alert('This gets called'); 
} 

实施例3:2

var foo = 'abcdefg'; // Declared with value 
if(foo){ 
    alert('Works'); 
} 

// No declaration 
if(foo){ // This will throw an error and your script stops executing. 
    alert('This does not get called'); 
} 
1

变量_被赋予值this。其余的只是宣布但未分配