Live data from Hacker News

The jQuery Divide:Understand where jQuery ends and JavaScript begins

slideshare.net

61–70 of 78 posts

Re: The jQuery Divide:Understand where jQuery ends and JavaScript begins

#61

Earlier quoted context omitted.

Well there's a few problems with that example: 1) You've got a "global" named a and then a local variable (via the argument) inside the each function called "a"...so that really confuses things. 2) a[i] where a is a jQuery object returns an unwrapped DOM element...what you want is .index(). 3) What you're doing is sort of roundabout... Why not: var d = $('div'), a = $('a'); a.each(function(i, el){ d.text(d.text() +'…

Shouldn't the second one be: var d = $('div'), a = $('a'); a.each(function(i, el){ d.text(d.text() +' '+ a.eq(i).text() ); }); Using eq(i) rather than index(i)?

I feel like this should have been the first replay to my rant. The nodes are already wrapped in the jQuery object, just need to use eq to access them by index. I've never seen that before, thanks

Re: The jQuery Divide:Understand where jQuery ends and JavaScript begins

#62

People at my job call all JavaScript jQuery, it is so annoying. Even more annoying is that their code (jQuery or not) plain sucks

When I use jQuery (MooTools is my lib of choice) I find myself using it in ways that is very unlike the majority of jQuery that is seen around the web. I absolutely hate the plugin system simply because you cannot easily get the instance of the plugin an refer to it later. To answer this I use function constructors with the module pattern (its easy and doesnt require an extra lib to get going) to create my plugins. A…

Cant edit, but my second argument, creating an array containing already jQuery wrapped elements is null.

There is a method called .eq() that allows you to select from the collection and it returns the element wrapped for you.

Re: The jQuery Divide:Understand where jQuery ends and JavaScript begins

#63
post #44

Earlier quoted context omitted.

Interacting with the DOM is what's slow. It's especially slow if the native querySelectorAll method isn't available because any non-trivial selections necessitate iterating over the DOM tree. That's why you don't want to re-query a selection multiple times. That's also why it's recommended that all selections start with an id. The size of the tree to iterate over can be quickly reduced using the native getElementByID…

> Also, in your first example, you don't have to rewrap containers[index] in a jQuery object. All the elements in the selection are already wrapped. Really? I think that is the whole point of this long comment thread -- that the elements in a collection arent already wrapped. http://jsfiddle.net/8nqtA/ This doesnt work unless i wrap a[i] in $() But like you're saying, it may be fruitless since the dom is the bottlene…

Ah yeah, I forgot you had to use .eq().

Re: The jQuery Divide:Understand where jQuery ends and JavaScript begins

#65
jQuery is popular because you don't need any programming experience to be productive. I was introduced to jQuery by our in-house web designer like 3 years ago because he used it and really liked it. He spoke HTML, the DOM and CSS and so does jQuery. And there are far more HTML/CSS literate people doing Javascript than there are CS-educated software engineers doing Javascript. In fact most software engineers I know don't know crap about Javascript. Thankfully I read "Javascript: The Good Parts" and have a much better appreciation for the language.

I also like jQuery as well. If you're doing simple DOM manipulation, AJAX and light javascript work it's hard to do any better. But I think there are superior choices for some more heavy lifting JS projects.

Re: The jQuery Divide:Understand where jQuery ends and JavaScript begins

#66

People at my job call all JavaScript jQuery, it is so annoying. Even more annoying is that their code (jQuery or not) plain sucks

I left a job where I'd built a simple UI to a complex back-end using jQuery. A former co-worker told me the guy who'd taken over that project kept complaining that he didn't understand "all this JSON" in the app.

Friend: "Can I see some of the JSON?" In-over-his-head Developer: "Sure, here." Friend: "That's not JSON, that's jQuery." Dev: "Whatever, it's the same thing." Friend: "No it's not and you thinking it is, is the real problem here."

Re: The jQuery Divide:Understand where jQuery ends and JavaScript begins

#67
Since no particular solutions were offered in the talk...

HN: What are the best technologies for writing large JS apps?

I have experience writing Closure (http://code.google.com/closure/) and its structure is pretty scalable, but it feels like so much effort to do simple things. Styling the widgets is a pain. Making a custom widget (extending goog.ui.Component) is surprisingly difficult to get right for even simple extensions.

After all that, I still think it's probably better to develop in that over jQuery -- at least you end up with a straightforward, modular, testable structure at the end of the day.

Is there something better? backbone?

Re: The jQuery Divide:Understand where jQuery ends and JavaScript begins

#68
post #39
post #35

Earlier quoted context omitted.

> jQuery as commonly used leads, in my personal experience, to hard-to-maintain programs. People using jQuery improperly is not something wrong with jQuery. jQuery is perfectly fine for large web applications, you just need to organize your code properly, with something like a MVC and ORM layer.

One can always argue "you're doing it wrong". People say the same about ror and perl. But in my experience, even with a good mvc and object model, and world-class folks, complex applications in jquery tend to become hard to maintain. I believe part of the reason is the tight coupling of state and events to the DOM. I'm also very skeptical of the dozen-odd undocumented "extensions" to the selector language. They are u…

it's documented here http://api.jquery.com/first-selector/

Re: The jQuery Divide:Understand where jQuery ends and JavaScript begins

#69

Earlier quoted context omitted.

Shouldn't the second one be: var d = $('div'), a = $('a'); a.each(function(i, el){ d.text(d.text() +' '+ a.eq(i).text() ); }); Using eq(i) rather than index(i)?

I feel like this should have been the first replay to my rant. The nodes are already wrapped in the jQuery object, just need to use eq to access them by index. I've never seen that before, thanks

you can also pull these out as standard DOM objects if you access as an array, ie. $('a')[0]

Re: The jQuery Divide:Understand where jQuery ends and JavaScript begins

#70

I don't see it mentioned very often, but google's closure-library has some really phenomenal patterns for building maintainable javascript. Its worth checking out Michael Bolin's book, Closure: The Definitive Guide, which goes in depth of the Component and Control frameworks. I've been using the library for 2 or 3 years now, and I am always surprised to see it has such a small community.

Exactly. I see closure as an ambitious effort to make JavaScript a better language for real complicate applications.
Post reply on HN