Posts

Showing posts from August, 2012

One Place to Another

Image
We're leaving for the tour on Friday and getting into LA at midnight - playing with friends all the way to Vancouver.  Another run of shows begin later next month in France and end in Italy.  See you all very soon. NC

A Safer JS Environment

Oh well, apparently I wasn't joking here and I went even further ... so here I am with a weird hack you probably never thought about before ;) A Globally Frozen Environment Have you ever thought about this in the global context? Object.freeze(this); Apparently not even browser vendors such Chrome or Safari since this condition, today, is always false: Object.isFrozen(Object.freeze(this)); , and even if it works as expected after freezing. Firefox and node.js got it right while Opera Next throws an error .. but latter a part ... Stop Any Global Pollution That's right, if you freeze the window or global object, guess what happens here: Object.freeze(this); var a = 123; alert(this.a); // undefined alert(a); // error: a is not defined We cannot even by mistake create a global variable ... there's no lint that could miss that. Moreover, if you are worried about malicious code able to change some global function or constructor, you can stop worrying with proposed freeze call: t...

Why JSON Won ... And Is Good As It Is

I keep seeing developers complaining about different things with JSON protocol and don't get me wrong, I've been the first one trying to implement any sort of alternative starting from JSOMON and many others ... OK? Well, after so many years of client/server development is not that I've given up on thinking " something could be better or different ", is just that I have learned on my skin all reasons JSON is damn good as it is, and here just a few of these reasons. Reliable Serialization ? No , 'cause YAGNI . There are few serialization processes I know that kinda work as expected and since ever, PHP serialize is a good example. Recursion is not a problem, is part of the serialization process to solve it, as well as classes together with protected and private properties. You can save almost any object within its state, even if this object won't be, as reference, the same you serialized .. and I would say: of course ! There are also two handy methods, _...

JavaScript recent Bits and Bobs

Quick post about few things landed, or not yet, in JavaScript world. preciseTime() In this era loads of +new Date , JSC offers since quite a while a handy global function called preciseTime() . Since this function offers more accuracy than milliseconds, and I am talking about microseconds, which is 1/1000 of a millisecond, it's the best option we have to measure benchmarks or be sure that some time elapsed between two statements in a synchronous code flow. You might don't know that a loop between new Date and another new Date could produce completely unexpected results such a negative integer which is kinda unexpected since zero is the best case we would consider. This behavior is behind ticks and clocks , more or less same reason setTimeout or setInterval have never been accurate in therms of delay. preciseTime , this is the obvious name of my latest git repository, could be shimmed or polyfilled quite easily via a node module I can't npm install for some reason,...