r/javascript • • Nov 03 '11

jQuery vs Plain old javascript

http://raynos.org/blog/14/jQuery-vs-POJS
0 Upvotes

53 comments sorted by

View all comments

0

u/Wolfy87 Nov 03 '11

@raynos I agree completely. Would love to know your thoughts on MooTools though. I use it in pretty much every project but only when required.

If some site only has one event to show an element I will polyfill the events myself (attatchEvent -> addEventListener, I hate you Microsoft) and save the page weight 20kb or so.

I havent moved into using micro libraries yet. Although I have loved coding my EventEmitter. I can see the benefits of using these small specific libraries over huge all purpose ones.

It's quite nice to add your own $ shortcut too.

(function($) {
    var myElement = $('myElement');
}(document.getElementById));

1

u/raynos Nov 03 '11

I heard you like promoting broken code.

var $ = document.getElementById

$("foo"); // throws error

MooTools is a better library then jQuery, although personally I just use the DOM-shim.

1

u/Wolfy87 Nov 03 '11

Derp. Sorry about that. You actually have to make the $ shortcut run document.getElementById. Like this.

function $(id) {
    return document.getElementById(id);
}

The DOM shim looks great. Well done! It's nice to have the classes that MooTools provides. Although native ones will be a lot better they do the job.

I am sure there is a micro framework for classes anyway.

2

u/raynos Nov 03 '11

Well there's pd. All the sugar you need to make ES5 OO easy.