Possible Duplicate: Why would a javascript variable start with a dollar sign? I see people using the dollar sign in front of variables when using jQuery. Is there any reason behind this? I'm I missing something basic or is it just a common practice? It's a common reference to a jQuery wrapped object. It makes reading the code easier to know which variables are jQuery wrapped. //
可能重复: 为什么JavaScript变量会以美元符号开头? 我看到人们在使用jQuery时在变量前面使用美元符号。 这背后有什么理由吗? 我错过了一些基本的东西,还是仅仅是一种常见的做法? 这是一个jQuery包装对象的常见参考。 它使得阅读代码更容易知道哪些变量是jQuery包装的。 //Item has been "cached" for later use in the script as a jQuery object. var $item = $(this); 对我来说一个普通的做法是: 如果一个
When a local (inner) function is declared in JavaScript, there are two options: Declaring with var keyword, assigning to the variable: (function() { var innerFunction1 = function() { ... }; innerFunction1(); }()); Declaring just with the function keyword, without assigning to variable: (function() { function innerFunction2() { ... }; innerFunction2(); }()); I can see one adv
当在JavaScript中声明本地(内部)函数时,有两种选择: 使用var关键字声明,分配给变量: (function() { var innerFunction1 = function() { ... }; innerFunction1(); }()); 用function关键字声明,而不分配给变量: (function() { function innerFunction2() { ... }; innerFunction2(); }()); 我可以看到第二个优点:可以在调用它的代码下面声明该函数,以便将私有函数与实际执行的代码分开。 哪个
This question already has an answer here: JavaScript plus sign in front of function name 3 answers Try not to: function() { return 1; }() then you will get Uncaught SyntaxError: Unexpected token ( JavaScript parser runs in two modes, lets call it expression mode and normal mode, in normal mode JS parser expects top level declarations like functions and code blocks. You use '(' to
这个问题在这里已经有了答案: JavaScript加上函数名称前面的3个答案 尽量不要: function() { return 1; }() 那么你将得到Uncaught SyntaxError: Unexpected token ( JavaScript解析器以两种模式运行,我们称它为表达模式和普通模式,在正常模式下,JS解析器需要顶层声明,如函数和代码块。 使用'('进入表达式模式,在表达式模式下function() { }将被解释为常量,其值是一个函数。 对象文字也有类似的情况
This question already has an answer here: What does a tilde do when it precedes an expression? 5 answers JavaScript plus sign in front of function name 3 answers
这个问题在这里已经有了答案: 在表达式之前,代字号在做什么? 5个答案 JavaScript加上函数名称前面的3个答案
This question already has an answer here: Why do you need to invoke an anonymous function on the same line? 19 answers JavaScript plus sign in front of function name 3 answers Javascript anonymous function call [duplicate] 4 answers With a return value.. you negate that with ! var x=!function(){return false}(); console.log(x); // true double negation var pizza='pizza'; var x=!!functio
这个问题在这里已经有了答案: 为什么你需要在同一行上调用匿名函数? 19个答案 JavaScript加上函数名称前面的3个答案 Javascript匿名函数调用[复制] 4个答案 随着返回值..你否定了! var x=!function(){return false}(); console.log(x); // true 双重否定 var pizza='pizza'; var x=!!function(){return pizza}(); console.log(x); // true // returns true if pizza is defined, not 'pizza' // returns false if
This question already has an answer here: JavaScript plus sign in front of function name 3 answers The + lets the js engine make the difference between this function expression and a function definition. For more readability, we usually use (function() { return 10; })(); See related article
这个问题在这里已经有了答案: JavaScript加上函数名称前面的3个答案 +让js引擎在这个函数表达式和一个函数定义之间做出区别。 为了更易读,我们通常使用 (function() { return 10; })(); 见相关文章
This question already has an answer here: JavaScript plus sign in front of function name 3 answers looking at this other question (JavaScript plus sign in front of function name) on the same subject, the following seems to be the answer: It forces the parser to treat the part following the + as an expression. This is usually used for functions that are invoked immediately source - https:
这个问题在这里已经有了答案: JavaScript加上函数名称前面的3个答案 在同一主题上查看另一个问题(JavaScript加上函数名前的符号),下面的答案似乎是: 它强制解析器将+后的部分视为表达式。 这通常用于立即调用的函数 源 - https://stackoverflow.com/a/13341710/970847 它强制解析器将+后的部分视为表达式。 这通常用于立即调用的函数。 从这里JavaScript加上函数名前的符号
This question already has an answer here: JavaScript plus sign in front of function name 3 answers To guide the javascript parser, that the thing written near the unary operator + is an expression. EDIT: You can create javascript functions anonymously. This is one of the syntaxes to create the same. By doing so, when they are called (ie evaluated), they act like a returning a function val
这个问题在这里已经有了答案: JavaScript加上函数名称前面的3个答案 为了引导javascript解析器,在一元运算符+附近写的东西是一个表达式。 编辑:您可以匿名创建JavaScript功能。 这是创建相同的语法之一。 通过这样做,当它们被调用(即被评估)时,它们就像返回一个函数值一样。 你可以从第二个链接中获得更多的信息,这个链接提供了很好的描述。 这个链接解释得很好 一旦声明,如果没有命名,它们可以象IIFE一
This question already has an answer here: JavaScript plus sign in front of function name 3 answers Any of those symbols turn the function that follows it into a function expression, instead of a function declaration. Putting them all in there together is just for fun. If you try to call a regular function by putting () right after the declaration: function () { // this is a syntax err
这个问题在这里已经有了答案: JavaScript加上函数名称前面的3个答案 任何这些符号都会将后面的函数转换为函数表达式,而不是函数声明。 把他们放在一起只是为了好玩。 如果您尝试通过在声明后立即放置()来调用常规函数: function () { // this is a syntax error... }(); 你会得到一个语法错误: SyntaxError:意外的标记( 因为你不能调用函数声明。 所以人们通常在圆括号中包含一个匿名函数,将其转换为
This question already has an answer here: JavaScript plus sign in front of function name 3 answers I think it forces the parser to treat the part following the + as an expression. You can also read Immediately-Invoked Function Expression Also check JavaScript plus sign in front of function name
这个问题在这里已经有了答案: JavaScript加上函数名称前面的3个答案 我认为它迫使解析器将+的部分视为表达式。 您也可以读取立即调用的函数表达式 还要检查函数名称前面的JavaScript加号