Live data from Hacker News

The jQuery Divide:Understand where jQuery ends and JavaScript begins

slideshare.net

51–60 of 78 posts

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

#51

Earlier quoted context omitted.

No alternatives? Coffeescript is always an alternative to js: http://jashkenas.github.com/coffee-script/

Coffeescript "compiles" to JS--so it's not an alternative to using Javascript; just an alternative syntax for writing javascript.

Coffeescript is a different language though. It has different grammar, different keywords and so on. It shares the same object model, and it is usually used on compile form.

There are other alternatives as well[1], such as:

- LLVM languages: http://syntensity.blogspot.com/2011/04/emscripten-10.html

- HotRuby: http://hotruby.yukoba.jp/

- Smalltalk: http://clamato.net/

- Haxe: http://haxe.org/

- Mascara: http://www.mascaraengine.com/

And so on. Coffeescript is just closer to javascript than most alternatives. But it is a different language, and a nicer one in my humble opinion.

[1] https://github.com/jashkenas/coffee-script/wiki/List-of-lang...

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

#52
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…

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() +' '+ $(this).text() );
    });

Or if you really want to do it your way:

    var d = $('div'),
        a = $('a');

    a.each(function(i, el){
         d.text(d.text() +' '+ a.index(i).text() );
    });

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

#53

Earlier quoted context omitted.

No alternatives? Coffeescript is always an alternative to js: http://jashkenas.github.com/coffee-script/

Coffeescript "compiles" to JS--so it's not an alternative to using Javascript; just an alternative syntax for writing javascript.

Well, yeah, but you might as well say that JavaScript is just an alternative syntax for writing assembly language or machine code.

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

#54
post #36
post #18

About time someone came out and said this, good job.

Said what? Did I miss it? He seemed to just stop midway. He implied there was a problem, showed some code, but never showed where the problem lies or what it was, and certainly never mentioned any solution. All I got was some vague "this isn't pretty" vibes.

The problem is, "this isn't pretty" is pretty much all we've got. There is very little information on how to organize javascript apps, or how to write javascript at all. Nobody knows the solution yet.

Most of the stuff on javascript programming is bullshit. "Javascript, The Good Parts" from Douglas Crockford is good. But it is only a start, we need more of that. The majority of books is trying to apply OOP design patterns or plainly translate GoF. I'm sure we can do better now.

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

#55

Earlier quoted context omitted.

Well given that a lot of the "pro" jQuery tips say that one should avoid rerunning the selector in favor of some sort of memoization: $('.class').doSomehting(); $('.class').doSomethingElse(); $('.class').thirdThing(); in favor of var ele = $('.class'); ele.doSomething(); ele.doSomethingElse(); ele.thirdThing(); I would only assume that re-querying with the jQuery object inside of event handlers has the same adverse e…

>why is the practice of rerunning the same selector frowned upon? Rerunning the same selector is frowned upon for (at least) 2 reasons: 1) It can make for more readable code. Sometimes it makes more sense semantically to have a local variable that describes the role of an element in the particular block of code you are working on, rather than just what selector you are using to get at the element. Also, it makes the…

Thanks for the reply, I get what you're saying and agree to an extent, the question was rhetorical though.

> Your map function (which has the arguments reversed fyi)

Oh god, jquery is php.

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

#56

Earlier quoted context omitted.

> 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…

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)?

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

#57
post #36

Earlier quoted context omitted.

Said what? Did I miss it? He seemed to just stop midway. He implied there was a problem, showed some code, but never showed where the problem lies or what it was, and certainly never mentioned any solution. All I got was some vague "this isn't pretty" vibes.

I can't speak to what else you missed or didn't miss, but you do seem to have missed that he is a she, so ...

doesn't change the original point

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

#58
I don't like presentations like this. What suggestions or solutions were offered? Perhaps the audio mentioned some good resources to use to learn how to properly architect a complex, Javascript/JQuery heavy application, or perhaps I just missed it in the slides, but to me it just seemed like a rant. Sure it's identifying an issue but it would be a whole lot more useful if it gave some links to books/articles/etc with details on how to layout your code in a maintainable manner.

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

#59

Earlier quoted context omitted.

Coffeescript "compiles" to JS--so it's not an alternative to using Javascript; just an alternative syntax for writing javascript.

Coffeescript is a different language though. It has different grammar, different keywords and so on. It shares the same object model, and it is usually used on compile form. There are other alternatives as well[1], such as: - LLVM languages: http://syntensity.blogspot.com/2011/04/emscripten-10.html - HotRuby: http://hotruby.yukoba.jp/ - Smalltalk: http://clamato.net/ - Haxe: http://haxe.org/ - Mascara: http://www.mas…

I disagree that any language that "compiles" into another language can be considered an "alternative." I'm not bashing CoffeeScript; I haven't played with it much and don't know enough about it say anything one way or the other; but at the end of the day, the result is still Javascript.

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

#60
post #58

I don't like presentations like this. What suggestions or solutions were offered? Perhaps the audio mentioned some good resources to use to learn how to properly architect a complex, Javascript/JQuery heavy application, or perhaps I just missed it in the slides, but to me it just seemed like a rant. Sure it's identifying an issue but it would be a whole lot more useful if it gave some links to books/articles/etc with…

I'd encourage you to bear in mind the original audience of the presentation: the very small number of experienced JavaScript developers who managed to obtain a ticket to the 2010 JSConf.eu in Berlin.

The goal of this presentation wasn't to teach people how to write good JavaScript -- many of the people in the room that day can and do write circles around me. Rather, the goal was to urge them, the experienced JS devs who are inventing the answers to these questions, to take seriously the need for creating exactly the information you point out to be lacking, and to be intellectually rigorous and honest in discussions of various solutions.

I'd suggest that you pay extra attention to the presentation starting at slide 40, and especially to what I said on slide 60: "Sharing what we know is as important as making new things." That, in a nutshell, was the message I sought to convey to the audience in October.

Post reply on HN