News for hackers. Stuff that matters.
Re:From jQuery to JavaScript and back again by crazygringo on Friday February 08, 2013 @11:05AM (#5188462)
> The reason being is that it abstracts out a lot of the JavaScript “gotchas” into nice, easy function calls. Most errors are caught by jQuery and never seen by the user, but more dangerously, never seen by the developer.

I have no idea what he's talking about. jQuery normalizes browser differences, but what on earth kinds of "errors" are "caught" by jQuery, that are "dangerous" to hide from the developer? I mean, I've used jQuery on projects for years, and I can't even imagine.

Re:From jQuery to JavaScript and back again by joshuahedlund on Friday February 08, 2013 @11:33AM (#5188645)
A lot of javascript causes errors if you try to do stuff on non-existent elements:

> document.getElementById("nonexistent").innerHTML = "";

This however will not cause any errors, it just won't do anything:

> $("#nonexistent").html("");

These sort of do-nothing-but-don't-throw-an-error responses can encourage developers to be less careful about making sure elements exist as they are expected, etc.

Re:From jQuery to JavaScript and back again by camus on Friday February 08, 2013 @12:19PM (#5188910)
since $("foo") returns a jQuery object that has a method html then it is valid , like [].forEach(myFunc) is valid: a empty array is not an error. there may be other relevant cases but i dont think this one is.
Re:From jQuery to JavaScript and back again by joshuahedlund on Friday February 08, 2013 @12:35PM (#5189017)
That's precisely my point. To put it another way, jQuery converts what would be a javascript error into a technically "valid" empty array. Sometimes this is useful, but it can also help mask poor logic.
Re:From jQuery to JavaScript and back again by camus on Friday February 08, 2013 @01:52PM (#5189459)
I doing agree, it is not a javascript error ! again if i take the array exemple and the following code :

    var a = [1,2,3,4]
    // now i filter the array
    var b = a.filter(function(a){return a<0} );
    // b = []
    // now do something on b
    b.forEach(function(e){console.log(e)})
    // will "fail" silently , because it will output nothing
is what i'm doing stupid ? yes, but it is 100% valid from a javascript perspective. It is a coding error , but not a JS error.