Vanilla JS, fast, lightweight, cross-platform framework
121–130 of 134 posts
Re: Vanilla JS, fast, lightweight, cross-platform framework
#122can be written as
jQuery.post('path/to/api',{banana:yellow},function(data){alert("Success: "+data);});
much simpler and easy than
var r = new XMLHttpRequest(); r.open("POST", "path/to/api", true); r.onreadystatechange = function () { if (r.readyState != 4 || r.status != 200) return; alert("Success: " + r.responseText); }; r.send("banana=yellow");
nevermind got the joke. but i think jQuery helps write faster code sometimes
Re: Vanilla JS, fast, lightweight, cross-platform framework
#123Earlier quoted context omitted.
The jquery one will be doing a lot of extra useless inefficient grunt work Such as?
"Useless" is subjective, but the jQuery object does a lot of extra work above the vanilla example. $ isn't just a syntax layer on top of querySelectorAll. When you do $('p'), it first queries the DOM for everything that matches that selector, then it creates new jQuery objects to wrap each of the returned nodes as well as creating a jQuery object to contain them. If all you're doing is setting the innerHTML of these…
[1] https://github.com/jquery/jquery/blob/master/src/manipulatio...
Re: Vanilla JS, fast, lightweight, cross-platform framework
#124Re: Vanilla JS, fast, lightweight, cross-platform framework
#125Earlier quoted context omitted.
I am a c developer, now I want to learn jQuery , but its syntax seems so weird to me, Vanilla JS looks more comfortable to me , one questions, does it supported by webkit?
I'm sorry. I don't know if you're joking or are serious. But if you're a C programmer and have no experience with JS I guess it must be really easy to be fooled by this "joke". Some JS people (the ones usually with a long beard) hate how kids use frameworks like jQuery and this site is an attempt at telling them "The vanilla JS, i.e. the standard language that all browsers use and your cool jQuery leverage under the…
Re: Vanilla JS, fast, lightweight, cross-platform framework
#126Given how optimized jquery is, does anyone understand why something as simple as getting an element by id would be so much slower than Dom methods?
I'm surprised by the number of comments like this. jQuery has to parse the selector and figure out that it's of the form "#id". This requires running a regular expression. A lot more is happening. The whole jQuery call from start to finish takes 2.85 microseconds, in what is presumably a real benchmark, but microbenchmarks like this are hard to interpret and basically meaningless. But yes, if your app needs to do a b…
Seems like you might have some other optimization work to do at that point :)
Re: Vanilla JS, fast, lightweight, cross-platform framework
#127Earlier quoted context omitted.
That's ES3. You have no reason to choose that way anymore - ES5 loops work everywhere current, can be polyfilled into IE8, and don't require any boilerplate stuff. var paragraphs = document.getElementsByTagName('p'); paragraphs.forEach(function(paragraph){paragraph.innerHTML = 'Hello.';})
Except #forEach is a method of Array, and getElementsByTagName does not return an Array but a NodeList. Which doesn't have any of Array's methods (it has a length, it can be indexed, and it has an alternative indexation method - #item — but it's not an array at all)
but never mind:
Array.forEach.call(paragraphs, function(paragraph){paragraph.innerHTML = 'Hello.';})
will work fine.
Re: Vanilla JS, fast, lightweight, cross-platform framework
#128Earlier quoted context omitted.
This enumeration is done the wrong way. You enumerate over a DOM node list which looks like an array, which includes enumerable properties like "length". This means that the variable "p" at some point will be "length" and "length".innerHTML = "..." will produce an error. The proper way is: for( var i=0, ps=document.getElementsByTagName('p'), len=ps.length; i < len; i++) {ps[i].innerHTML = 'Hello.';}
I'm a JS noob, but I though 'length' was not enumerable (i.e. its 'enumerable' property is set to 'false'). Edit: I think I missed what you said. You're saying it's "like" and array, but unlike arrays its `length` is enumerable. I'll leave my comment so other skeptics can benefit :) Edit2: This is what I was referring to (read the 'Note' at the right side): http://bonsaiden.github.com/JavaScript-Garden/#object.forinl…
paras = document.getElementsByTagName('p') for (var para in paras) { console.log(para)} 0 1 ... 9 10 length item
Re: Vanilla JS, fast, lightweight, cross-platform framework
#129ANYWAY, Lol at that... made me chuckle.
Re: Vanilla JS, fast, lightweight, cross-platform framework
#130I can't be the only one getting tired of sites like this making the front page. Really? It would be one thing to see someone write a legitimate article on why they think the move to JS frameworks is harmful and/or the benefits of using plain JS, and for that to make it to the front page. I'd be interested in that perspective. But this is just somebody being snide. It's the internet equivalent of the kid on The Simpso…
Reading the example code I learned enough to become interested in vanilla javascript. Although satirical in tone, I found it insightful. It lead me to question the necessity of using jQuery for every project.