Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery or pure javascript [closed]

Would a JavaScript programmer, that knows JavaScript pretty well, write his/her code in JQuery or in pure JavaScript ?

In other words, is JQuery just for people who don't know JavaScript very well?

Lets say we are talking about creating "company presentation websites", where JavaScript mainly will be be used for animations.

like image 462
Hakan Avatar asked Dec 21 '11 10:12

Hakan


3 Answers

jQuery isn't a separate programming language. It's a JavaScript library. Whether you use jQuery or not, it's still "pure JavaScript".

JavaScript is designed for both functional and object-oriented programming. And with any non-trivial application, a good programmer will likely make use of these tools to help write clean, maintainable, and efficient code.

When you group a set of functions/objects/types/etc. together that can be reused, you're creating a library—whether you give that library a name or not. Any good programmer knows to do this in order to reuse source code, provide convenience/utility functions, and avoid writing the same code over and over again for common tasks.

John Resig just happened to have created an excellent library for DOM manipulation that he's released under a generous open source license, and it's one that promotes a coding style many programmers enjoy, so it's become very popular.

I think it's safe to say that John Resig knows JavaScript pretty well, and he sure as hell uses jQuery. And if that doesn't reflect poorly on his programming abilities, then why should it reflect poorly on anyone else who uses jQuery?

Lastly, a good developer isn't defined by how much of the code in a project they wrote on their own. If you're a lonewolf hacker who likes to roll his own, that's fine. But the quality of a developer should be reflected by the quality of the end results they produce. If you build a CMS by yourself without using any pre-existing libraries or frameworks or collaborating with anyone, but it's all spaghetti code that exhibits tight coupling and violates DRY, then the fact that you wrote it all by yourself without the use of any pre-existing libraries means very little.

I think most clients would probably prefer you'd taken advantage of any off-the-shelf solutions that fit the job which could have helped complete the project in less time and produce better results.

like image 134
Lèse majesté Avatar answered Sep 23 '22 12:09

Lèse majesté


In Jquery you write a lot less with the same effect (usually takes a little bit slower, but it does not bother anyone) ussualy without declaring temporary var`s. Maybe otherwise for example:

$('a').click (function () {/* blabla */ }).css ({/* some css here */});

In pure javascript that one line can be presented by:

var links =  document.getElementsByTagName("a") // in modern browsers = document.querySelectorAll("a");
for(var i =links.length; i--;){ 
    var l = links[i];
    l.addEventListener("click", function(){  //bla bla},true);
    l.style.someCssAtrribute = 'someValue'
   //etc
}

Although jQuery weighs around 100kb in return you write a lot less and more clearly

like image 30
abuduba Avatar answered Sep 19 '22 12:09

abuduba


I like to think I know javascript well, but hated using it until I learned Jquery. With jquery I write code faster that is easier for others to read and easier to maintain. Why wouldn't you use it?

like image 25
Matt Avatar answered Sep 23 '22 12:09

Matt