Posts

Showing posts with the label scope

JavaScript Protected Properties

Imagine this simple piece of code: var obj = { _name: "protected", gimmeName: function () { return this._name; } }; obj.gimmeName(); // "protected" obj._name; // throws new Errror now, imagine I have the simplest solution ever, compatible with both ES5 and ES3 genric implementations ... now please keep reading to know a bit of background :) The JS Meaning Of Protected JS developers know that in JavaScript properties are always public and that it is possible to attach/detach properties in any moment to a generic object. Regardless this fact, many libraries consider protected, by naming convention, all those properties whose name start with "_" . You Are Doing It Wrong First of all I keep saying that is a common error trying to bring classical Object Oriented concepts into a completely different language as JavaScript is, but it does not matter ... we want protected stuff, right? Due dynamic nature, the common protected meaning is point...

Internet Explorer Scope Resolution

I have enclosed in only 5 steps JScript weirdness, hoping all precedent deliriums about functions, standards, and Internet Explorer, will make more sense now. Here there is the link to original HTML slides , I hope this will help everybody to have clearer ideas.

Named function expressions demystified

Update If after this reading things are still the same, please read the part 2 of this post , thanks. This is a re-post, and few considerations, about the good Juriy article , which I suggest for every JavaScript developer with a deeper knowledge than just an API (jQuery or others). Github For Everything! My first consideration is about github, something I've never used that much since via Google Code I feel pretty comfortable with subversion. I find truly interesting the way Juriy is tracking his documentation, I've never thought about an article, as my old JavaScript Prototypal Inheritance could be, in a code repository as kangax did: good stuff! My Alternative Solution There are few extra consideration to do over Juriy explanation, plus minor inconsistencies. The first thing is that Internet Explorer basically manages Function expressions and Function declarations in the same way, there's no such VS in the middle. The fact we assign the function to a whatever named v...

a new Relator object plus unshared private variables

This is a Robert Nyman 's post dedicated reply, about JavaScript inheritance and alternatives and private variables . First of all, I would like to say thanks to Robert for both interesting articles He is writing about JS inheritance, and a link to a personal comment which aim was to bring there my "old" documentation about classical JavaScript inheritance and usage of prototype, closures, and public, privileged, or private, scope when we create a constructor. About Last Rob's post talk about private variables, describing them as shared, if present outside the constructor, and valid only for singleton instances. This is true, and could cause a lot of headache if we are not truly understanding closures and prototype shared methods behaviour, but there is a way to use this peculiarity about shared private variables to create dedicated private variables. Before I will write about it, let's look into a generic shared private variable example: Click = function(){ ...

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