strange anonymous javascript function call

This question already has an answer here: What does the exclamation mark do before the function? 9 answers And you are right, it is an Immediately-Invoked Function Expression (IIFE) You can rewrite !+-+-+!+-+-+!+-+-+!+-+-+!+-+-+!+-+-+!+-+-+!+-+-+! function(d, w){ ... }(document, window); to !function() { ... }() and it still works. This is because ! is a unary operator (just l

奇怪的匿名javascript函数调用

这个问题在这里已经有了答案: 该功能之前感叹号做了什么? 9个答案 你说得对,它是一个立即调用函数表达式(IIFE) 你可以重写 !+-+-+!+-+-+!+-+-+!+-+-+!+-+-+!+-+-+!+-+-+!+-+-+! function(d, w){ ... }(document, window); 至 !function() { ... }() 它仍然有效。 这是因为! 是一元运算符(就像+ , -和~ - 见https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Expressions_and_Operators)。

JavaScript !function(){}

This question already has an answer here: What does the exclamation mark do before the function? 9 answers !function(a){/* ... */}(); Using an unary operator to invoke an IIFE is common practice. That's a common shorthand for: (function(a){/* ... */}()); or: (function(a){/* ... */})(); You can also substitute the not unary operator with any other unary operator: -function(a){ /* ..

JavaScript!function(){}

这个问题在这里已经有了答案: 该功能之前感叹号做了什么? 9个答案 !function(a){/* ... */}(); 使用一元运算符来调用一个IIFE是常见的做法。 这是一个常见的简写: (function(a){/* ... */}()); 要么: (function(a){/* ... */})(); 您也可以用其他一元运算符替换非一元运算符: -function(a){ /* ... */ }(); +function(a){ /* ... */ }(); /* ... etc. */ 给函数调用提供了一个很好的解释https://github.com/air

what does !function in Javascript mean?

This question already has an answer here: What does the exclamation mark do before the function? 9 answers It is short-hand or alternative of self-invoking anonymous function: (function(){ // code })(); Can be written: !function(){ // code }(); You can also use + instead of ! . If you simply did: function(){ // code }(); That will create problems, that's why you need to ad

Javascript中的功能是什么意思?

这个问题在这里已经有了答案: 该功能之前感叹号做了什么? 9个答案 它是自我调用匿名函数的简写或替代方法: (function(){ // code })(); 可以写成: !function(){ // code }(); 你也可以用+代替! 。 如果你只是做了: function(){ // code }(); 这会产生问题,这就是为什么你需要添加! 在将函数声明转换为函数表达式之前 。 引用文档第12.4节: ExpressionStatement不能以function关键字开头,因为这

How exactly does !function(){}() work?

This question already has an answer here: What does the exclamation mark do before the function? 9 answers What the ! does When you use ! , the function becomes the single operand of the unary (logical) NOT operator. This forces the function to be evaluated as an expression, which allows it to be invoked immediately inline. Other alternatives You can do this with just about any ope

function(){}()如何工作?

这个问题在这里已经有了答案: 该功能之前感叹号做了什么? 9个答案 什么! 不 当你使用! 该函数成为一元(逻辑)NOT运算符的单个操作数。 这迫使函数被评估为一个表达式,这可以立即以内联方式调用它。 其他选择 你可以用几乎所有的操作员来做到这一点。 这里有些例子... 'invoke',function(){ /*code*/ }(); 1+function(){ /*code*/ }(); void function(){ /*code*/ }(); ~function(){ /*code*/ }(); +functio

Javascript anonymous function call

This question already has an answer here: What does the exclamation mark do before the function? 9 answers When the keyword function is met in a statement position (as the first token in a statement), the function declaration is expressed as a function statement. Function statements are hoisted to the top of the scope, cannot be immediately invoked and must have a name. When the keyword i

Javascript匿名函数调用

这个问题在这里已经有了答案: 该功能之前感叹号做了什么? 9个答案 当在语句位置(作为语句中的第一个标记)满足关键字function ,函数声明被表示为函数语句。 函数语句被提升到范围的顶部,不能立即调用并且必须有一个名称。 当关键字在表达式中被满足时(即不是在语句中的第一个标记,在你的示例中!是第一个标记),函数声明被表达为一个函数表达式,它可以是匿名的并返回新创建的功能。 由于它返回新创建函数的值,

How does Access

Apparently, I have completely misunderstood its semantics. I thought of something like this: A client downloads javascript code MyCode.js from http://siteA - the origin . The response header of MyCode.js contains Access-Control-Allow-Origin: http://siteB , which I thought meant that MyCode.js was allowed to make cross-origin references to the site B. The client triggers some functionality

Access如何

显然,我完全误解了它的语义。 我想到了这样的事情: 客户端从http:// siteA下载JavaScript代码MyCode.js - 来源 。 MyCode.js的响应头包含Access-Control-Allow-Origin:http:// siteB ,我认为这意味着MyCode.js被允许对站点B进行跨源引用。 客户端触发MyCode.js的一些功能,而这些功能又向http:// siteB发出请求,尽管它们是跨域请求,但应该没问题。 那么,我错了。 它根本就不能这样工作。 因此,我已阅读跨

Should I use JSLint or JSHint JavaScript validation?

I am currently validating my JavaScript against JSLint and making progress on, it's assisting me to write better JavaScript - in particular in working with the Jquery library. I have now come across JSHint , a fork of JSLint . So I am wondering for web applications, which are very much JavaScript was driven, which is the better or most applicable validation tool to work against: JSLint

我应该使用JSLint还是JSHint JavaScript验证?

我目前正在验证我的JavaScript和JSLint并取得进展,它帮助我编写更好的JavaScript - 特别是在使用Jquery库时。 现在我所遇到JSHint,JSLint的的一个分支。 所以我很想知道Web应用程序,这是非常多的JavaScript驱动,这是更好或最适用的验证工具来处理: JSLint或JSHint? 我想现在决定验证机制并向前推进,将其用于客户端验证。 jshint和jslint之间的区别? 请在单个javascript例子中解释。 链接: jshint - ht

module.exports vs exports in Node.js

I've found the following contract in a Node.js module: module.exports = exports = nano = function database_module(cfg) {...} I wonder whats the different between module.exports and exports and why both are used here. Setting module.exports allows the database_module function to be called like a function when required . Simply setting exports wouldn't allow the function to be exported

module.exports vs Node.js中的导出

我在Node.js模块中找到了以下合约: module.exports = exports = nano = function database_module(cfg) {...} 我想知道module.exports和exports之间有什么不同,以及为什么两者都用在这里。 设置module.exports允许database_module时要调用的函数的功能等required 。 简单地设置exports将不允许导出函数,因为节点导出对象module.exports引用。 以下代码不允许用户调用该函数。 module.js 以下将无法使用。 exports =

define variable with/without var prefix in javascript

This question already has an answer here: What is the purpose of the var keyword and when should I use it (or omit it)? 18 answers In global scope, there is no difference, unless you using it again: var my_var; will redeclare it, while my_var; will be simply useless expression. There is a difference only when not in global context. Ex1 (with var): var x = 0; (function(){ var x = 1;

在javascript中使用/不使用var前缀定义变量

这个问题在这里已经有了答案: var关键字的用途是什么,什么时候应该使用它(或省略它)? 18个答案 在全局范围内,除非再次使用它,否则没有区别: var my_var; 将重新声明它,而my_var; 将会是无用的表达。 只有当不在全球范围内时才有区别。 Ex1(含变种): var x = 0; (function(){ var x = 1; alert('fx: '+ x); })(); alert('gx: '+ x); //fx: 1 //gx: 0 Ex2(无var): x = 0; (function(){ x =

What is the difference between var x=1 and x = 1 in NodeJs

This question already has an answer here: What is the purpose of the var keyword and when should I use it (or omit it)? 18 answers 'var x = 3' will create a variable within the current scope. Given this is declared in a function, x will not be available outside it, unless explicitly returned. 'x = 3' will create a variable within the global scope. Thus, any other code can

NodeJs中var x = 1和x = 1之间的区别是什么?

这个问题在这里已经有了答案: var关键字的用途是什么,什么时候应该使用它(或省略它)? 18个答案 'var x = 3'将在当前范围内创建一个变量。 鉴于这是在函数中声明的,除非明确地返回,否则x将不在其外部可用。 'x = 3'将在全局范围内创建一个变量。 因此,任何其他代码都可以访问并更改其值。 在全局范围内使用变量通常是不好的做法。