Hacker News new | past | comments | ask | show | jobs | submit login

I wonder if that code block does anything at all.

    var http = new XMLHttpRequest();
    if (http != undefined) {
        ...
    }
In what runtime would calling this constructor return undefined (or null, or false...), and yet not throw an error?



You're right, that code will blow up if the browser doesn't support XMLHttpRequest. The version below is more common:

    var ajaxObject;
    if (window.XMLHttpRequest) {
      ...
    } else if (window.ActiveXObject) {
      ...
    }
    
    if (ajaxObject) {
      ...
    } else {
      //handle users without ajax
    }
and that's just to create the object! compare to:

    $.ajax();


and that's just to create the object! compare to: $.ajax();

So you're comparing the body of one function to the signature of another? I know I posted some really shitty code, but you managed to shoot yourself in the foot even in that scenario, grats.

https://github.com/jquery/jquery/blob/master/src/ajax.js

Here, now it's apples to apples.


you realize i'm talking about code I have to write, right? If anything, you've further proven my point, considering that the jQuery implementation also covers other common use cases like failure, cross-browser requests, etc., i.e. hours upon hours of googling and/or just copy-pasting the jQuery source into my app, which adds loading time to my site instead of just using a cached version of jQuery that almost everyone already has in the cache in the first place.


When I look at that, I see man-years of work that I don't have to reinvent.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: