+function ($) { "use strict";

}(window.jQuery); 怎么理解?

匿名函数闭包

我们先来理一理函数表达式和函数声明的区别

函数表达式 函数可以是匿名函数,也可以有函数名,但是这种函数无法直接使用,只有通过表达式左侧的变量来调用。

var a = function(){
alert('Function expression');
}
var b = new a();

函数声明:必需要有函数名 

function a(){
alert('Function declaration');
}
a();

下面是一个匿名函数

function () {

}

一元操作符+和函数表达式

也可以使用如-,~,!这种其它的一元操作符或者括号,目的是告诉解析器在这些特定操作符附近的是一个表达式(注意,JS将function当作一个函数声明的开始,而函数声明后面不能跟圆括号直接进行调用,所以有的时候想办法将函数声明转化为函数表达式)

The following are three classical methods 三种典型方式进行上述转换

+function () { 

};

(function () {

});

void function() {

};

The efficiency of these three kinds of

Operators addition and subtraction counter, operator "~" (bit reverse) the definition in the EMCAScript5: according to operator binding statement; the old value into a 32 bit integer; execution operator after the statement; conversion of the line for 32 bit and returns the result.

"()"Group operators: returns the expression results in the execution of the.

void: According to operator binding statement execution, return undefined. 
The group operator also needs to perform the statement and returns the value returned by the contrast statement block, void multiple access block operation, thus the performance of void in this case is better than the group of operators.

 吧拉粑粑拉粑粑拉吧拉吧拉吧没看明白不好意思!


Through the end of the () to call and run 通过在表达式末尾加()运行

+function () { 

}();

(funtion () {

})();

Parameter passing, in order to avoid the $and other library or template that conflict, window.jQuery passed as parameters.

参数传递,为了避免$和其他库或模板发生冲突,jquery用这种方式起作用

+function (x) {
console.log(x);
}(3); +function ($) { }(window.jQuery);

Another advantage is that, within the scope of the JS interpreter, can quickly find $object than this method.

 其它优势在于,在JS解释器中,这种方式下的效率更高

$(function(){  

});

There is a way, to avoid naming conflicts.

避免冲突的另一种方式

var j = jQuery.noConflict();
j('#someDiv').hide();
$('someDiv').style.display = 'none';// Other libraries$

A look of writing something like the code. This code initializes the jQuery code in the DOM loading is complete.

这种写法,代码将在DOM加载完毕时初始化Jquery代码

$(function(){ 

}); 

This is equivalent to the

和下面这种写法作用相同

$(document).ready(function(){
// Initialize the jQuery code in the DOM loading is complete. 
});
Different from 和这种不同
$(window).load(function(){
// In the picture, the media file is loaded, the initialization of jQuery code.
});

In strict mode 严格模式下的情况我暂时先不研究了,等日后水平上来再进一步学习

The establishment of "strict mode", mainly in the following: norms, efficiency, safety, facing the future

  Remove the Javascript grammar some unreasonable, not rigorous, reduce some strange behavior;

  - remove some safety code operation code, ensure operation safety,

  - to improve the compiler efficiency, increase running speed,

  - in order to pave the way for future versions of Javascript.

Enter "sign in strict mode", is the following statement:   

"use strict";

The old version of the browser will send it as an ordinary string, ignore them.

The "use strict" in the first line of the script file, the script will be "strictly" mode of operation.

If this statement is not in the first row, is invalid, the script is run in "normal mode".

If the code files of different patterns was merged into one document, this requires special attention.

(strictly speaking, as long as the front is not to produce practical results of the sentence, "use strict" may not be in the first line, such as direct as in an empty semicolon. )

<script>
"use strict";
console.log("This is strict mode. ");
</script>
<script>
 console.log("This is the normal mode. ");
</script>

The "use strict" in the first line of the function body, the entire function to "strict" mode of operation.

function strict(){
"use strict";
return "This is strict mode. ";
}
function notStrict() {
return "This is the normal mode. ";
}

Because calling the method above is not conducive to the files, so it is better, the following method, the script file in an anonymous function is executed immediately.

+function (){  "use strict";

}();

The scope of strict mode constraint

Var declare variables. In strict mode, variable must use the VaR command to display the statement, and then use the.

"use strict";
v = 1; // Error, V is not a statement
for(i = 0; i <2; i++) { // Error, I is not a statement }

Numbers don't add 0. Disable the octal algorithm because... Because the octal is not included in the ECMAScript, the digital front 0 will change the meaning of numbers, JS will think is an octal number, thus error.

"use strict";
var sum = 015 + // Error! syntax error
197 +
142;

Do not allow the function non top, it is not allowed to function nesting. ECMAScript5 (or ECMAScript3) are not allowed.

"use strict";
if (true){
function f() { } // Error! syntax error
f();
} for (var i = 0; i <5; i++){
function f2() { } // Error! syntax error
f2();
} function baz(){ // kosher
function eit() { } // also kosher
}

Don't use these words do variables or parameters implements, interface, let, package, private, protected, public, static, yield. In strict mode as the reserved keywords. Future ECMAScript seems to cut into the pre.

function package(protected){ // Error!
"use strict";
var implements; // Error! interface: // Error!
while (true){
break interface; // Error!
} function private() { } // Error!
}
function fun(static) { 'use strict'; } // Error!

Console implementation of strict mode returns undefined

(function(){ return this; })()
 
Window {top: Window, window: Window, location: Location, external: Object, chrome: Object…} (function(){ 'use strict'; return this; })()
undefined

There are other examples

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/Strict_mode?redirectlocale=en-US&redirectslug=JavaScript%2FReference%2FFunctions_and_function_scope%2FStrict_mode

Document ready immediately

!function ($) {

  $(function(){

  })

}(window.jQuery)


问题二:


												

+function ($) { "use strict";}(window.jQuery);全面分析的更多相关文章

  1. 转载 +function ($) { "use strict";}(window.jQuery);全面分析

    转载 https://www.cnblogs.com/cndotabestdota/p/5664112.html +function ($) { "use strict";}(wi ...

  2. 笔记:IIFE 立即执行的函数表达式 +function ($) { }(window.jQuery);

    在Bootstrap源码(具体请看<Bootstrap源码解析1>)和其他jQuery插件经常看到如下的写法: +function ($) { }(window.jQuery); 这种写法 ...

  3. JQuery安全分析

    JQuery安全分析: JQuery的风险均来源于对输入的数据没有进行有效性检验.客户端的Javascript需要检验:来源于服务器的数据.来源于当前页面的用户输入,服务器端需要检验来源于用户端的数据 ...

  4. (转)function($){}(window.jQuery) 是什么意思?

    function(){}(); (function(){})(); 这两个是self-invoking anonymous 自调匿名函数,用这类的方法,能强制使匿名函数成为表达式,把不合法变成合法. ...

  5. Activity Threa创建Window和View分析

    http://blog.csdn.net/ljsbuct/article/details/7094580 1. 入口. 以前一直都说Activity的人口是onCreate方法.其实android上一 ...

  6. window.jQuery || document...

    window是浏览器端的全部数据变量的引用.比如 window.window === window window.jQuery 就是浏览器中的全局变量里的jQuery那为什么不写 jQuery 而是写 ...

  7. window.jQuery || document.write("<script src='__PUBLIC__/assets/js/jquery.js'>"+"<"+"/script>")

    今天无意中看到这样一段代码 <script type="text/javascript"> window.jQuery || document.write(" ...

  8. CDN失效时使用本地js文件:window.jQuery || document.write

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></ ...

  9. jQuery框架分析第一章: 第一个匿名函数

    我的jQuery版本为1.7* 这个版本代码比之前的版本优化了很多,结构也清晰了不少,就用最新的吧. 打开jQuery源代码 首先你能看到所有代码被一个 (function(window,undefi ...

随机推荐

  1. android 防止反编译的若干方法

    第一种方式:混淆策略 混淆策略是每个应用必须增加的一种防护策略,同时他不仅是为了防护,也是为了减小应用安装包的大小,所以他是每个应用发版之前必须要添加的一项功能,现在混淆策略一般有两种: 对代码的混淆 ...

  2. python select.select模块通信全过程详解

    要理解select.select模块其实主要就是要理解它的参数, 以及其三个返回值.select()方法接收并监控3个通信列表, 第一个是所有的输入的data,就是指外部发过来的数据,第2个是监控和接 ...

  3. miniUI Grid添加汇总行,Grid绑定数据,IDEA免编译设置

    坑1: 2017-6-5周二,上午解决了昨天摸索一下午的问题,使用miniui显示汇总行数据,要点有这么几个 在创建Grid div的时候一定要加上以下两个属性: //显示汇总行开关 showSumm ...

  4. 学习MQ(二)基本概念

    学习MQ(二)基本概念 这次简单罗列一下MQ的基本概念,还有我对它们的理解 1.queue manager 队列管理器,这是MQ系统中最上层的一个概念.每一个queue manager都有一个侦听器, ...

  5. JavaScript设计模式之一封装

    对于熟悉C#和Java的兄弟们,面向对象的三大思想(封装,继承,多态)肯定是了解的,今天我想讲讲如何在Javascript中利用封装这个特性,开讲! 我们会把现实中的一些事物抽象成一个Class并且把 ...

  6. FFMpeg编译之路

    为了编译这个东西,快折腾了一个星期了.期间经历了很多痛苦的过程,今天我把整个过程,以及在这个过程的感悟写下来,以备日后查看,也希望能帮到一些像我一样的兄弟姐妹. 在这一个星期里前前后后加起来总共使用了 ...

  7. 实例解析Collections源码,Iterator和ListIterator

    比如一个视频或文章有多个页面标签设置,我们在看一篇文章或一个视频时,底部有为你推荐栏目. 如何根据这个文章或视频的标签,来实现这个推荐栏目呢. public List<VideoInfoVo&g ...

  8. 当今商业中使用的三种十分重要的IT应用系统

    本文为读书笔记,其中内容摘自<信息时代的管理信息系统>第八版第二章 当今商业中使用的三种十分重要的IT应用系统: 供应链管理(SCM) 客户关系管理(CRM) 电子协同(e-collabo ...

  9. 设置firefox每次访问网页时检查所存网页的较新版本

    我们做技术,经常在写页面的时候需要多次刷新测试,可是浏览器都有自己的缓存机制,一般CSS和图片都会被缓存在本地,这样我们修改 的CSS就看不到效果了,每次都去清空缓存,再刷新看效果,这样操作太麻烦了. ...

  10. SOFA 源码分析 —— 过滤器设计

    前言 通常 Web 服务器在处理请求时,都会使用过滤器模式,无论是 Tomcat ,还是 Netty,过滤器的好处是能够将处理的流程进行分离和解耦,比如一个 Http 请求进入服务器,可能需要解析 h ...