News for hackers. Stuff that matters.
Re:Vanilla JS, fast, lightweight, cross-platform framework by ams6110 on Sunday August 26, 2012 @02:43PM (#4435822)
The jquery version is easier to write, and less prone to error, but in the native version it's much more clear what's actually going on.
Re:Vanilla JS, fast, lightweight, cross-platform framework by mibbitier on Sunday August 26, 2012 @02:58PM (#4435883)
Also in the native version, you know you're only doing the work required. The jquery one will be doing a lot of extra useless inefficient grunt work to achieve nothing. Making it incredibly slow in comparison.
Re:Vanilla JS, fast, lightweight, cross-platform framework by vidarh on Sunday August 26, 2012 @03:45PM (#4436004)
Premature optimization, and all that. It is trivial to get raw dom nodes out of jQuery, so you can easily use jQuery to begin with and replace any code with the full DOM API calls should it every become a performance issue.

This discussion is a bit like how assembly programmers used to defend not moving to a high level language long after the performance benefits were not worth it any more.

Re:Vanilla JS, fast, lightweight, cross-platform framework by MatthewPhillips on Sunday August 26, 2012 @06:10PM (#4436416)
> This discussion is a bit like how assembly programmers used to defend not moving to a high level language long after the performance benefits were not worth it any more.

But we're not at that point in the web yet. The performance benefits are worth it. Just try out JQuery Mobile if you want to see what wasted CPU cycles can do.

Re:Vanilla JS, fast, lightweight, cross-platform framework by vidarh on Sunday August 26, 2012 @07:00PM (#4436583)
It may be worth it for specific use cases, just like there are certainly still specific use cases where assembly shines.

The point is we're well past the point where grasping for the asm-equivalent from the start should be the default unless you happen to specifically target one of those niches.

Re:Vanilla JS, fast, lightweight, cross-platform framework by MatthewPhillips on Sunday August 26, 2012 @07:05PM (#4436595)
Mobile isn't a niche.
Re:Vanilla JS, fast, lightweight, cross-platform framework by dasil003 on Sunday August 26, 2012 @07:57PM (#4436732)
That depends on the application.
Re:Vanilla JS, fast, lightweight, cross-platform framework by lukeschlather on Sunday August 26, 2012 @06:37PM (#4436509)
It depends on what you're trying to do. Mostly, I try to write code that displays the same in every possible browser without special-casing or using confusing idioms. CPU cycles are cheap. A webpage that loads a little slow is a possible lost sale. A webpage that fails to load is a definite lost sale.
Re:Vanilla JS, fast, lightweight, cross-platform framework by tripzilch on Tuesday August 28, 2012 @08:09PM (#4446476)
> It is trivial to get raw dom nodes out of jQuery, so you can easily use jQuery to begin with and replace any code with the full DOM API calls should it every become a performance issue.

That's still going to be a lot of work if the performance issues turn out to be many separate jQuery calls spread all over your code, which is not unlikely.

Re:Vanilla JS, fast, lightweight, cross-platform framework by rhizome on Sunday August 26, 2012 @04:08PM (#4436065)
The jquery one will be doing a lot of extra useless inefficient grunt work

Such as?

Re:Vanilla JS, fast, lightweight, cross-platform framework by xionon on Sunday August 26, 2012 @06:34PM (#4436502)
"Useless" is subjective, but the jQuery object does a lot of extra work above the vanilla example.

$ isn't just a syntax layer on top of querySelectorAll. When you do $('p'), it first queries the DOM for everything that matches that selector, then it creates new jQuery objects to wrap each of the returned nodes as well as creating a jQuery object to contain them.

If all you're doing is setting the innerHTML of these objects, it's a non-trivial overhead.

Re:Vanilla JS, fast, lightweight, cross-platform framework by Xion on Monday August 27, 2012 @06:43AM (#4438207)
It creates just one jQuery object to wrap the entire array of DOM nodes. Afterwards, .html() is essentially innerHTML [1], provided jQuery can use it directly (otherwise it has to create DOM nodes by itself).

[1] https://github.com/jquery/jquery/blob/master/src/manipulatio...

Re:Vanilla JS, fast, lightweight, cross-platform framework by batista on Sunday August 26, 2012 @03:52PM (#4436014)
>but in the native version it's much more clear what's actually going on.

Yes, but it's also more probable that it won't go on at all (due to browser incompatibilities and such).