Combining two event handling into a single event handling

This question already has an answer here: jQuery multiple events to trigger the same function 10 answers Or you can define the function: function mySuperDuperEventHandler() { $(!agent) { var milk = $().height(), choco = $().width(); doThis(); } else { var orange = $().length(), apple = $().width(); orThis(); } } A

将两个事件处理组合成单个事件处理

这个问题在这里已经有了答案: jQuery多个事件触发相同的功能10个答案 或者你可以定义该功能: function mySuperDuperEventHandler() { $(!agent) { var milk = $().height(), choco = $().width(); doThis(); } else { var orange = $().length(), apple = $().width(); orThis(); } } 然后将其分配为事件处理程序: $(window).on('load

JQuery function on window events: combine load and resize

This question already has an answer here: jQuery multiple events to trigger the same function 10 answers jQuery允许您将事件侦听器分配给多个事件类型。 $(window).on('load resize', function(){ if ($(window).width() <= 992) { //mycode } }) 你可以使用你现有的代码,然后触发resize()事件: $(window).resize(function () { if ($(window).width() <= 992) { //mycode }

窗口事件的JQuery函数:结合加载和调整大小

这个问题在这里已经有了答案: jQuery多个事件触发相同的功能10个答案 jQuery允许您将事件侦听器分配给多个事件类型。 $(window).on('load resize', function(){ if ($(window).width() <= 992) { //mycode } }) 你可以使用你现有的代码,然后触发resize()事件: $(window).resize(function () { if ($(window).width() <= 992) { //mycode } }).resize();

Javascript immediately invoked function patterns

What do you call these patterns? What is the difference between them? When would you use each? Are there any other similar patterns? (function() { console.log(this); // window })(); (function x() { console.log(this); // window })(); var y = (function() { console.log(this); // window })(); var z = function() { console.log(this); // window }(); EDIT: I just found two mor

Javascript立即调用函数模式

你称这些模式是什么? 他们有什么区别? 你什么时候使用每个? 还有其他类似的模式吗? (function() { console.log(this); // window })(); (function x() { console.log(this); // window })(); var y = (function() { console.log(this); // window })(); var z = function() { console.log(this); // window }(); 编辑:我只是发现了两个看起来多余的方法,通过命名后两种情况下的功能来做到这一

!function ($) { }(window.jQuery) what is this code for?

Possible Duplicate: What is the purpose of this? (function ($) { //function code here })(jQuery); What does the exclamation mark do before the function? negating self invoking function? !function ($) { … }(window.jQuery); !function ($) { $(function() { . . . }) }(window.jQuery) I saw this in a jquery example and was wondering what the !functi

!函数($){}(window.jQuery)这个代码是什么?

可能重复: 这样做的目的是什么? (function($){// function here here})(jQuery); 该功能之前感叹号做了什么? 否定自我调用功能? !函数($){...}(window.jQuery); !function ($) { $(function() { . . . }) }(window.jQuery) 我在一个jQuery的例子中看到了这个,并且想知道!function($){}(window.jQuery)的用途是什么。 特别是感叹号对我来说是新的

negating self invoking function? !function ($) { ... }(window.jQuery);

Possible Duplicate: What does the exclamation mark do before the function? I was looking through the Twitter Bootstrap JavaScript code and I noticed all their plugins are wrapped in negating self invoking functions. I am aware that function ($) { ... }(window.jQuery); invokes the function immediately. But what is the ! for? 1) if you just do: function () { /* ... */ }(); You will ge

否定自我调用功能? !函数($){...}(window.jQuery);

可能重复: 该功能之前感叹号做了什么? 我正在浏览Twitter Bootstrap JavaScript代码,我注意到他们的所有插件都被封装在否定自我调用函数中。 我知道function ($) { ... }(window.jQuery); 立即调用该函数。 但是,这是什么! 对于? 1)如果你只是这样做: function () { /* ... */ }(); 你会得到一个错误。 JS不允许你发布一个函数声明(因为“变量提升”的概念,这在技术上是不正确的,但对于很多人来说要容易

What's the difference between function(){}() and !function(){}()

Possible Duplicate: !function(){ }() vs (function(){ })() So I was just reading through the source of the new Bootstrap (2.0) from Twitter and noticed that there is an exclamation mark before the self-invoking anonymous function. When I saw this I immediately thought "Oh crap, there's a new, better way to do this?". See for yourself! http://markdotto.com/bs2/js/bootstrap-mo

function(){}()和!function(){}()之间有什么区别?

可能重复: !function(){}()vs(function(){})() 所以我刚刚阅读了Twitter上的新Bootstrap(2.0)的源代码,并注意到自调用匿名函数之前有一个感叹号。 当我看到这个时,我立即想到“噢,废话,有一个新的,更好的方法来做到这一点?”。 你自己看! http://markdotto.com/bs2/js/bootstrap-modal.js http://markdotto.com/bs2/js/bootstrap-dropdown.js http://markdotto.com/bs2/js/bootstrap-scrollspy.

what does `!function()` mean?

This question already has an answer here: What does the exclamation mark do before the function? 9 answers The preceding ! takes the un-parseable statement, and allows it to to be parsed by the JS engine, which in turn returns true. function(){}(); SyntaxError: Unexpected token ( !function(){}(); >>true Source

`!function()`是什么意思?

这个问题在这里已经有了答案: 该功能之前感叹号做了什么? 9个答案 前面! 采用不可解析的语句,并允许它由JS引擎解析,而JS引擎则反过来返回true。 function(){}(); SyntaxError: Unexpected token ( !function(){}(); >>true 资源

Why create an anonymous function with a ! before it?

Possible Duplicate: What does the exclamation mark do before the function? What's the point of the ! in the snippet bellow? !function ($) { // code }(window.jQuery); This syntax is used extensively in Twitter's bootstrap.js they are calling the function right after the declaration (with window.jQuery as a parameter) another syntax is: (function ($) { // code })(wind

为什么创建一个匿名函数! 在之前呢?

可能重复: 该功能之前感叹号做了什么? 这是什么意思! 在片段波纹管? !function ($) { // code }(window.jQuery); 这个语法在Twitter的bootstrap.js中被广泛使用 他们在声明后立即调用函数(使用window.jQuery作为参数) 另一种语法是: (function ($) { // code })(window.jQuery); 有些人更关心一个字符而不是可读性

javascript function leading bang ! syntax

I've been seeing this syntax on a few libraries now and I'm wondering what the benefit is. (note i'm well aware of closures and what the code is doing, I'm only concerned about the syntactical differences) !function(){ // do stuff }(); As an alternative to the more common (function(){ // do stuff })(); for self invoking anonymous functions. I'm wondering a few thing

JavaScript功能领先砰! 句法

我现在已经在几个图书馆看到了这个语法,我想知道它的好处是什么。 (注意我很清楚闭包和代码在做什么,我只关心语法上的差异) !function(){ // do stuff }(); 作为更常见的替代方案 (function(){ // do stuff })(); 用于自我调用匿名函数。 我想知道几件事情。 首先,什么是允许顶级示例实际工作? 为了使这个语句在语法上正确,为什么需要爆炸? 我被告知也有+作品,而且我相信其他人会取代! 其次,有什么好

What is the purpose of a self executing function in javascript?

In javascript, when would you want to use this: (function(){ //Bunch of code... })(); over this: //Bunch of code... Its all about variable scoping. Variables declared in the self executing function are, by default, only available to code within the self executing function. This allows code to be written without concern of how variables are named in other blocks of javascript code. For

JavaScript中的自动执行功能的目的是什么?

在JavaScript中,你想什么时候使用这个: (function(){ //Bunch of code... })(); 在此: //Bunch of code... 其全部关于可变范围。 在自执行函数中声明的变量默认情况下仅适用于自执行函数内的代码。 这允许编写代码而不用担心变量在其他JavaScript代码块中的命名方式。 例如: (function(){ var foo = 3; alert(foo); })(); alert(foo); 这将首先提醒“3”,然后在下一次提醒时抛出一个错误,因为fo