Live data from Hacker News

Vanilla JS, fast, lightweight, cross-platform framework

vanilla-js.com

111–120 of 134 posts

Re: Vanilla JS, fast, lightweight, cross-platform framework

#112
post #29
post #18

Earlier quoted context omitted.

I'll take $('p').text('Hello.') over for (var p in document.getElementsByTagName('p')) { p.innerHTML = 'Hello.'; } any day!

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.';}

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.';})

Re: Vanilla JS, fast, lightweight, cross-platform framework

#113
post #57

Earlier quoted context omitted.

Aren't the polyfills pretty good nowadays?

Yes, but using all of them needed for full HTML5 support in, say, IE6, probably takes up more bandwidth than downloading a new browser.

It doesn't take up any more bandwidth if you're properly concatenating your JS.

Re: Vanilla JS, fast, lightweight, cross-platform framework

#114

Earlier quoted context omitted.

Yes, but using all of them needed for full HTML5 support in, say, IE6, probably takes up more bandwidth than downloading a new browser.

It doesn't take up any more bandwidth if you're properly concatenating your JS.

Uh, no. I think you misunderstand me.

Re: Vanilla JS, fast, lightweight, cross-platform framework

#115
post #68

Earlier quoted context omitted.

I think you missed the announcement where Microsoft is going to do a silent update of IE10 to consumer PC's. IE9 usage will drop to the low single digits within a year and IE10 will take its place as the leading IE browser.

How's this going to work for corporate installs? As much as I love the idea of big companies being forced forward, I have the nagging feeling that Microsoft will include a get-out-of-jail-free card for them. (Speaking as a medium-sized corporation user stuck on Snow Leopard. :] )

The "force" upgrade everyone is talking about is an optional thing. You will be able to go into the settings and turn that off (specifically for corporate use).

Re: Vanilla JS, fast, lightweight, cross-platform framework

#116
post #112
post #29

Earlier 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.';}

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.';})

This will not work - Check my solution below :)

document.getElementsByTagName returns a DOM Node List and it does not have forEach method according to the DOM spec. DOm Nodes, Elements and Node Lists and Node Maps do not follow the javascript spec (ECMAScript) hence do not share methdos and properties. A Dom Node List does not have the methods of the javascript array. That is because DOM Node List does not inherit from the Array.prototype, because it is not javascript - it has its own spec that exactly determines what methods and properties it should have. The implementation in the browser happens to be accessible through javascript but that does not mean that the DOM is part of javascript. That is why wrapper libraries like jQuery or other abstractions are necessary to make the DOM much more accessible from a JS perspective. BTW that is why many people confuse DOM with javascript and then get frustrated which is understandable.

Re: Vanilla JS, fast, lightweight, cross-platform framework

#117

Earlier quoted context omitted.

> jQuery is kind of a big download for mobile, so I often skip it for small tasks. That's what Zepto[0] is for: jQuery's API, 20% of the size (although it drops some features, e.g. $(selector) is pretty directly proxied to document.querySelectorAll, so $('> .foo') works in jQuery but blows up in Zepto) [0] http://zeptojs.com/

Ah, last I looked at Zepto, it's support for non-webkit browsers was pretty lacking. It's good to see they're making strides on the cross-platform comparability front. The supported browsers list looks pretty good now.

Been using it on mobile for about a year. It's small and snappy, and the people behind it are very responsive & opinionated in a good way.

Re: Vanilla JS, fast, lightweight, cross-platform framework

#118
post #25

I 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…

You're not the only one. Considering that the owner have ads on the site, gives evidence of someone who want to make a quick and easy buck from trolling the community.

Re: Vanilla JS, fast, lightweight, cross-platform framework

#119
post #112
post #29

Earlier 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.';}

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)

Re: Vanilla JS, fast, lightweight, cross-platform framework

#120
post #25

I 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.

How often are you selecting span elements? They serve different purposes. Do you due diligence of course.
Post reply on HN