Comments on: 76 bytes for faster jQuery https://j11y.io/javascript/76-bytes-for-faster-jquery/ Sun, 22 Mar 2015 15:39:22 +0000 hourly 1 https://wordpress.org/?v=5.0.13 By: Drew Wells https://j11y.io/javascript/76-bytes-for-faster-jquery/#comment-1911 Fri, 22 Oct 2010 16:03:49 +0000 https://j11y.io/?p=1517#comment-1911 This may help better understand how your shortcut works. The following code doesn’t work with jQuery.single:

_$().each([1,2,3],function(){});
//TypeError: Object 1,2,3 has no method 'apply'
$().each([1,2,3],function(){});
//Empty object returned w/jQuery set to prototype

This also gives different results:

_$([1,2,3]).each(function(n,i){ console.log(n,i); });
> 0 [1,2,3]
> Object returned first element is an array
$([1,2,3]).each(function(n,i){ console.log(n,i); });
> 0 1
> 1 2
> 2 3
> Array returned, extending jQuery
> Object

]]>
By: Alexsandro https://j11y.io/javascript/76-bytes-for-faster-jquery/#comment-1910 Sat, 28 Aug 2010 19:50:04 +0000 https://j11y.io/?p=1517#comment-1910 jQuery should care of cache carefully not completely, cos illegal usage I think probably cause slower or big list of cache items same using search list like binary list and whatever.

]]>
By: dust https://j11y.io/javascript/76-bytes-for-faster-jquery/#comment-1909 Thu, 20 May 2010 10:39:57 +0000 https://j11y.io/?p=1517#comment-1909 wow~~ learn more thing,mark

]]>
By: James https://j11y.io/javascript/76-bytes-for-faster-jquery/#comment-1908 Thu, 22 Apr 2010 21:08:59 +0000 https://j11y.io/?p=1517#comment-1908 @Graham, that’s a good idea — so, essentially, instead of having to call jQuery.single, the wrapped object could be passed to the each callback? I think I’m gonna bring this up on the jQ forums when I get a chance. ๐Ÿ™‚

@Marek, I had never heard of the “Flyweight pattern”, so thanks for bringing it up!

to remember all quirks and cross-browser issues is pointless to me

Well, obviously, knowing all quirks is out of the question, but I think at least a rudimentary understanding of potential points of unreliability is very important.

]]>
By: Marek Stasikowski https://j11y.io/javascript/76-bytes-for-faster-jquery/#comment-1907 Tue, 20 Apr 2010 22:08:12 +0000 https://j11y.io/?p=1517#comment-1907 Isn’t this http://en.wikipedia.org/wiki/Flyweight_pattern?
Would be cool to see jQuery be meeting more of actual computer science.
Oh, and as to DOM scripting – I don’t agree. It’s good to be aware that there is a href and id and whatever property on a DOM element, yet to remember all quirks and cross-browser issues is pointless to me. If I end up with a low performance application, I’ll profile it and remove those extra jQuery instances as needed. Perfection kills, worrying about optimization too much and too early is the root of all evil, etc. On the other hand, if a library has this shared flyweight object implemented, it automatically encourages it’s use (like in Ext JS).

PS.
Since I hear more and more of you people yelling to know the DOM API by heart, I’m actually printing out a cheat sheet and maybe consider using it from time to time. Maybe. ๐Ÿ™‚

]]>
By: Graham https://j11y.io/javascript/76-bytes-for-faster-jquery/#comment-1906 Fri, 16 Apr 2010 16:10:04 +0000 https://j11y.io/?p=1517#comment-1906 James, I meant something like this (my own library does something similar internally):

Group.prototype.forEach=function(fn){
	var l=this.length, wrapper=new Group([null]), i=0;
	for (;i < l;i++){
		wrapper[0]=this[i];
		fn(wrapper, i, this);
		}
	};
 
...
 
var mygroup=$("p");
mygroup.forEach(function(single){
	// single is an instance
	// single[0] is the node
	});

Only one wrapper object gets created.

]]>
By: James https://j11y.io/javascript/76-bytes-for-faster-jquery/#comment-1905 Tue, 13 Apr 2010 12:43:54 +0000 https://j11y.io/?p=1517#comment-1905 @Howard, I couldn’t agree more! ๐Ÿ™‚

]]>
By: Howard https://j11y.io/javascript/76-bytes-for-faster-jquery/#comment-1904 Fri, 09 Apr 2010 18:02:02 +0000 https://j11y.io/?p=1517#comment-1904 I would point to your first assertion: “Mr. Uber Cool jQuery Developer isnโ€™t accustomed to the DOM“, and point out that while jQuery is a great tool, it’s not a substitute for learning the native API. If you don’t know the DOM properties and methods, then Please Learn Them Now; you’ll be better for it.

]]>
By: James https://j11y.io/javascript/76-bytes-for-faster-jquery/#comment-1903 Fri, 09 Apr 2010 09:19:37 +0000 https://j11y.io/?p=1517#comment-1903 @Simon, good point, I’ll see if I can work something in.

@Graham, but there would still be implicit “wrapping”, which would cost just as much.

]]>
By: Graham https://j11y.io/javascript/76-bytes-for-faster-jquery/#comment-1902 Thu, 08 Apr 2010 12:40:00 +0000 https://j11y.io/?p=1517#comment-1902 I’ve only starting using jQuery recently and was surprised callbacks were passed the node on its own, rather than inside a jQuery wrapper. It would have been trivial to do the above inside the jQuery core before executing each callback.

]]>