Saturday 19 May 2012

JavaScript digest

Well, in the last weeks I've been going through a good bunch of new javascript stuff that I think well deserves a summary here (I admit this write up will mainly look like a digest of dailyJS

  • Global eval. To be truth, it's something that I've never needed myself, but when I came across the jQuery.globalEval function in the jQuery documentation I felt the need to check how that was done, and I didn't seem to make any sense of what was going in the source code, as it seemed to clash with my previous knowledge. Well, hopefully this explains it well. It's normal that the code didn't make sense to me, all this works based on some odd EcmaScript detail in the language specification.
  • JavaScript object literals are so handy, but from time to time I stumble upon the same issue, now at least I've found a good workaround. What happens if one of the properties you're initializing depends on other properties? you can't use this there, cause it will point to the this in that function scope, not to the new object that you're creating. You can't use the property name alone either... but you can use this neat code recommended here:
    var foo = {
       a: 5,
       b: 6,
       init: function() {
           this.c = this.a + this.b;
           delete this.init; //do this to keep the foo object "clean"
     return this;
       }
    }.init();
    
  • Even when I'm a loyal Mozilla fan, I tend to prefer node.js over Rhino. I find it terribly useful for unit testing your browser independent code or CLI development, nevertheless, I don't share all the frenzy about its usage for server side stuff. Maybe I'm old fashioned, but I still have not got to grips with the idea of NIO and just one thread. Yes, I know about the ck10 problem and so on... but I grew up (as a programmer) in a time where Threads were cool! Anyway, reading this online book about node.js is really interesting. It gives you the basis there for building your own web framework, which is a really mind stretching exercise and makes you better understand existing frameworks. The author also has a very clever article about Object.create and a classless society :-)
  • It may seem a bit odd that when we still can't use JavaScript 5 with full confidence due to the lack of implementation in some browsers (awful IE 6-7-8...) we start to talk about the next version. The thing is that this excellent video in infoQ got me rather excited about all the neat features they plan (many of them already seem approved) to add to ES.Next aka EcmaScript 6. I love the addition of Array Comprehensions, Generators, destructured assignment, proxies, but I admit that I'm not much happy with the addition of syntax for classes, as on the contrary, I think they should try to promote thinking in prototypes instead of thinking in classes. Anyway, as I understand that under the covers everything will still be based on prototype chains, I just see it as something to avoid. Then I found this post encouraging developers to try to take part in the process,
  • These excellent Front End Development Guidelines discuss also html and CSS, but anyway I think this entry is a good fit for them.

No comments:

Post a Comment