Posts

Showing posts with the label this

ES5 and function default scope

This is just a quick one. One of the worst decision about ES5, after the one to remove arguments.callee when "use strict" is present, is the missed default reference to the global object. Probably the most secure trick to retrieve the native window in JavaScript is this one: // wherever we are var global = function(){return this}(); // while window, could be simply a variable // assigned somewhere else in this scope I have already talked about this, and I am still against some ES5 "feature" which aim is probably the one to make JavaScript as fast as possible, regardless all code that will break if "use strict" is present in the generic scope. Another non-sense is to allow a this in a context where there is no this. Rather than an error, ES5 will point refer this to undefined . Are you kidding me? this is a special keywords related to the context and you are telling me a context is undefined? so I guess open() , as example, should throw an error there, s...

Famous documentation and the dark side of "this" !

The good thing of internet is that you can find a lot of free documentation. At the same time, the bad thing of internet, is that this documentation is rarely updated. It could be a "guru documentation" or it could be a newbie documentation, but in both cases, it doesn't matter because it is probably wrong, not updated, or too generic. This post has not enough space to describe every error you can find on, and off line ... so let me start with some true example about a common misunderstood referer, the this one. Douglas Crockford and Private Members in JavaScript This page is famous enough, and I suppose that every true JavaScript developer has read them at least once. The main error in that page is described in this sentence By convention, we make a private that parameter. This is used to make the object available to the private methods. This is a workaround for an error in the ECMAScript Language Specification which causes this to be set incorrectly for inner functio...