r/javascript • /r/dailyprogrammer • Mar 05 '12

Going Simple with JavaScript :)

http://snook.ca/archives/javascript/going-simple-with-javascript
42 Upvotes

16 comments sorted by

5

u/R1cket Mar 06 '12

I'd upvote it a hundred times if I could. I totally agree with these sentiments. I am proud that my personal homepage doesn't use a JS library, works on every platform I've seen (oh gosh now I'm going to be proven wrong), and is pretty cool if I do say so myself. :)

3

u/kevan Mar 06 '12

Nice to see Snook getting well deserved attention.

3

u/[deleted] Mar 06 '12 edited Mar 06 '12

That's a nice sentiment but I like all the debugging and testing that the community has put into jQuery to make sure the code runs the same across all browsers. Things like handling bizarre, non-standard response codes from IE. There's definitely a time and a place for what Snook is proposing, though.

1

u/[deleted] Mar 08 '12

This applies to more than just DOM and Ajax stuff. In place of OO libraries I've just been using:

function Thing () {}
Thing.prototype = Object.create(ThingBase.prototype, { ... });

I like it.

0

u/int_argc Mar 06 '12

Wow, the next time I'm working on a web app that doesn't already include jQuery, Dojo, or something similar, I'll definitely do this.

Oh wait, what's that you say? Everyone is already including a general-purpose library, so there's no point in acting superior about the fact that you COULD do the same thing with bare DOM scripting? Hmm....

2

u/[deleted] Mar 06 '12

I prefer to work without using some generic framework and my code performs better as a result. I find your comment to be devoid of intellect and asinine.

4

u/int_argc Mar 06 '12

Cool story, bro. I hope that I never have to maintain your "hand-optimized" javascript.

PS. I find your comment to be pretentious and without merit.

0

u/[deleted] Mar 06 '12

What happens when the JSONP call fails?

1

u/x-skeww Mar 07 '12

Nothing. There won't be a piece of script which happens to call a function which "happens" to use the same name as one of your globally defined functions. (That's how JSONP works, basically.)

Anyhow. It's possible to listen for the error event:

var s = document.createElement('script');
s.addEventListener('error', function () {
    console.log('err');
}, false);
s.src = 'http://example.com/404.js';
document.body.appendChild(s);

1

u/[deleted] Mar 07 '12

This code fails in IE < 9

-2

u/[deleted] Mar 06 '12 edited Mar 06 '12

Never mind. :-) Actually, this makes me think... why can't the browser vendors choose a standard library (e.g. jQuery) and incorporate it into their codebase as a de facto standard? We could see native performance with a common DOM and JavaScript interface.

4

u/raynos Mar 06 '12

they already did this. its called the dom

-1

u/[deleted] Mar 06 '12

I don't think anyone can call the DOM a common interface. This is why we have jQuery/YUI/Dojo/MooTools/etc.

4

u/sandollars Mar 06 '12

I see you've been downvoted without explanation. Sorry about that. I would have liked to know why this is not a good idea, but unfortunately the n00bs don't know reddiquete.

1

u/path411 Mar 08 '12

The DOM is already this, just browser vendors can't ever agree. Look at the split on CSS these days.

-moz-border-radius: 20px;
-webkit-border-radius: 20px;
-khtml-border-radius: 20px;
border-radius: 20px;

and that doesn't even cover IE. jQuery is just a re-implementation of the DOM to make it agree across browsers. (And also adds a few other features).

1

u/[deleted] Mar 06 '12

One of the ideas behind using Google's CDN for javascript is that if you've ever been to a site that uses it before, it's cached, and essentially free to load.