Bug Tracker

Ticket #1797 (closed feature: wontfix)

Opened 1 year ago

Last modified 11 months ago

Integrate extend-like Behavior in each

Reported by: j5 Assigned to: anonymous
Type: feature Priority: trivial
Milestone: 1.2.2 Component: core
Version: 1.2.1 Keywords: each DOM
Cc: Needs: Review

Description

Would like each method when passed an object instead of a function to merge the passed object onto the DOM element.

example:

jQuery("#somediv").each({innerHTML: "blah blah blah"});

This would give a shortcut to manipulating non-attribute fields of DOM objects (such as references to other DOM objects which have been attached).

I have modified jQuery-1.2.1.js each as follows to accomplish this:

	// args is for internal usage only
	each: function( obj, fn, args ) {
		if ( args ) {
			if ( obj.length == undefined )
				for ( var i in obj )
					fn.apply( obj[i], args );
			else
				for ( var i = 0, ol = obj.length; i < ol; i++ )
					if ( fn.apply( obj[i], args ) === false ) break;
		// A special, fast, case for the most common use of each
		} else {
			if ( obj.length == undefined )
				// modified to extend each to do an extend on the object returned with object passed
				for ( var i in obj ) {
					if (typeof fn == 'function')
						fn.call( obj[i], i, obj[i] );
					else if (typeof fn == 'object')
						for (var f in fn)
							obj[i][f]=fn[f];
				}
			else
				if (typeof fn == 'function')
					for ( var i = 0, ol = obj.length, val = obj[0];
						i < ol && fn.call(val,i,val) !== false; val = obj[++i] ){}
				else if (typeof fn == 'object')
					for ( var i = 0, ol = obj.length; i < ol; i++)
						for (var f in fn)
							obj[i][f]=fn[f];
		}
		return obj;
	},

Attachments

Change History

Changed 11 months ago by john

  • status changed from new to closed
  • type changed from bug to feature
  • resolution set to wontfix

I don't understand the logic of this addition. Why not just use .attr()?

Note: See TracTickets for help on using tickets.