Skip to main content

Bug Tracker

Side navigation

Ticket #2402: string_lambda_for_grep_and_map.patch
File string_lambda_for_grep_and_map.patch, 0.9 KB (added by markusb, March 07, 2008 12:07PM UTC)

I copied the string-lambda feature back from the previous release. I don't know why it has been removed.

Index: javascripts/jquery.js
===================================================================
--- javascripts/jquery.js	(revision 189)
+++ javascripts/jquery.js	(working copy)
@@ -1179,6 +1179,11 @@
 	},
 
 	grep: function( elems, callback, inv ) {
+		// If a string is passed in for the function, make a function
+		// for it (a handy shortcut)
+		if ( typeof callback == "string" )
+			callback = eval("false||function(a,i){return " + callback + "}");
+
 		var ret = [];
 
 		// Go through the array, only saving the items
@@ -1191,6 +1196,11 @@
 	},
 
 	map: function( elems, callback ) {
+		// If a string is passed in for the function, make a function
+		// for it (a handy shortcut)
+		if ( typeof callback == "string" )
+			callback = eval("false||function(a,i){return " + callback + "}");
+
 		var ret = [];
 
 		// Go through the array, translating each of the items to their

Download in other formats:

Original Format