Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rather than declaring empty anonymous functions all around, introduce…

… and use a single empty function. Thanks to Matt Kruse for the suggestion.
  • Loading branch information...
commit 6cb2945837ccca55204191a8e7a70b2b2486c28e 1 parent fe6c86d
@jeresig jeresig authored
Showing with 6 additions and 4 deletions.
  1. +2 −2 src/ajax.js
  2. +2 −0  src/core.js
  3. +1 −1  src/event.js
  4. +1 −1  src/offset.js
View
4 src/ajax.js
@@ -384,7 +384,7 @@ jQuery.extend({
// The request was aborted, clear the interval and decrement jQuery.active
if ( !xhr || xhr.readyState === 0 ) {
requestDone = true;
- xhr.onreadystatechange = function(){};
+ xhr.onreadystatechange = jQuery.noop;
// Handle the global AJAX counter
if ( s.global && ! --jQuery.active ) {
@@ -394,7 +394,7 @@ jQuery.extend({
// The transfer is complete and the data is available, or the request timed out
} else if ( !requestDone && xhr && (xhr.readyState === 4 || isTimeout === "timeout") ) {
requestDone = true;
- xhr.onreadystatechange = function(){};
+ xhr.onreadystatechange = jQuery.noop;
status = isTimeout === "timeout" ?
"timeout" :
View
2  src/core.js
@@ -464,6 +464,8 @@ jQuery.extend({
return true;
},
+ noop: function() {},
+
// Evalulates a script in a global context
globalEval: function( data ) {
if ( data && rnotwhite.test(data) ) {
View
2  src/event.js
@@ -427,7 +427,7 @@ jQuery.event = {
ready: {
// Make sure the ready event is setup
setup: jQuery.bindReady,
- teardown: function() {}
+ teardown: jQuery.noop
},
live: {
View
2  src/offset.js
@@ -121,7 +121,7 @@ jQuery.offset = {
body.removeChild( container );
body = container = innerDiv = checkDiv = table = td = null;
- jQuery.offset.initialize = function() {};
+ jQuery.offset.initialize = jQuery.noop;
},
bodyOffset: function( body ) {

4 comments on commit 6cb2945

@DBJDBJ

"noop" ? Isn't that: "no operation", abbreviated ? ... what was wrong with some combination of words "empty" and "function" ?
I think even: "emptyFunction" would work better.
After all in jQ we have "isArray", "isFunction" ...and other nice descriptive names ;o)

--DBJ

@rhacker

@DBJDBJ: It's no operation perform which is quite meaningful I think.

@mubasshir

@DBJDBJ @rhacker hi, in the end of 2014, noop has become a thing. Thanks for addition of awesome function

@DBJDBJ

@mubasshir thanks .. although for clarity sake I do maintain my position:

"noop" is not an empty function

function is not an operator, thus empty function can not be any kind of operator ...
ps: sometimes emptyFunction is also called nullFunction , which is also OK.

          var emptyFunction = nullFunction = function () { } ;
Please sign in to comment.
Something went wrong with that request. Please try again.