Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
John Resig authored December 31, 2009
4  src/ajax.js
@@ -384,7 +384,7 @@ jQuery.extend({
384 384
 			// The request was aborted, clear the interval and decrement jQuery.active
385 385
 			if ( !xhr || xhr.readyState === 0 ) {
386 386
 				requestDone = true;
387  
-				xhr.onreadystatechange = function(){};
  387
+				xhr.onreadystatechange = jQuery.noop;
388 388
 
389 389
 				// Handle the global AJAX counter
390 390
 				if ( s.global && ! --jQuery.active ) {
@@ -394,7 +394,7 @@ jQuery.extend({
394 394
 			// The transfer is complete and the data is available, or the request timed out
395 395
 			} else if ( !requestDone && xhr && (xhr.readyState === 4 || isTimeout === "timeout") ) {
396 396
 				requestDone = true;
397  
-				xhr.onreadystatechange = function(){};
  397
+				xhr.onreadystatechange = jQuery.noop;
398 398
 
399 399
 				status = isTimeout === "timeout" ?
400 400
 					"timeout" :
2  src/core.js
@@ -464,6 +464,8 @@ jQuery.extend({
464 464
 		return true;
465 465
 	},
466 466
 
  467
+	noop: function() {},
  468
+
467 469
 	// Evalulates a script in a global context
468 470
 	globalEval: function( data ) {
469 471
 		if ( data && rnotwhite.test(data) ) {
2  src/event.js
@@ -427,7 +427,7 @@ jQuery.event = {
427 427
 		ready: {
428 428
 			// Make sure the ready event is setup
429 429
 			setup: jQuery.bindReady,
430  
-			teardown: function() {}
  430
+			teardown: jQuery.noop
431 431
 		},
432 432
 
433 433
 		live: {
2  src/offset.js
@@ -121,7 +121,7 @@ jQuery.offset = {
121 121
 
122 122
 		body.removeChild( container );
123 123
 		body = container = innerDiv = checkDiv = table = td = null;
124  
-		jQuery.offset.initialize = function() {};
  124
+		jQuery.offset.initialize = jQuery.noop;
125 125
 	},
126 126
 
127 127
 	bodyOffset: function( body ) {

2 notes on commit 6cb2945

dbj

"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

Dung Quang

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

Please sign in to comment.
Something went wrong with that request. Please try again.