Posts

Showing posts with the label Caja

google caja, what's wrong with "new" ?

In JavaScript we mainly have two type of variables: primitives (string, number, boolean, null or undefined) object related (Array, Object, Function, unknown for IE) Due to this difference, a primitive string and a new String are two different worlds: var s1 = "abc"; var s2 = new String("abc"); s1 instanceof String; // false s2 instanceof String; // true The nature of primitive constructor is to return a typeof constructor, but if we use new in front of the same constructor, it will obviously return an instance of that constructor. This is the nature of javascript, summarized in this snippet: function I1(){ return 1; }; function I2(){}; var i1 = new I1(); var i2 = new I2(); In both cases, o1 and i2 will be respectively an instanceof I1, and I2. In few words, if a function is caled via new , the assigned value will be an instance o the constructor itself or, if it returns an instanceof Something , the instanceof something value. function I3(){ return n...