Posts

Showing posts with the label native

More standard Stack, and more slim ArrayObject

I have just updated both Stack and ArrayObject constructors. The Stack improvement is About concat method, now truly standard, accepting arguments that are not instance of Stack or Array. var s = new Stack(1, 2, 3); alert(s.concat([4, 5], 6)); // 1,2,3,4,5,6 Since this method uses defined slice one, there is no more reason to redefine concat method in inherited prototypes. That is why ArrayObject does not need anymore concat method, for a total of 4 fast redefined methods, plus inherited concat. ArrayObject is now the fastest extended Array constructor that returns instances of the same constructor, ArrayObject. ArrayObject is, at the same time, the base to create every other kind of cool library, using native Array methods power. Enjoy!

Habemus Array ... unlocked length in IE8, subclassed Array for every browser

History I do not know how many time, during these years, JavaScript Ninjas tried to subclass the native Array to create libraries over its powerful methods without losing performances. I have finally discovered the way to remove locked length from Internet Explorer 8 , and to solve problems with every other browser. We tried to inherit Array instead of Object This is where my last trip started, simply looking at arguments behaviour. It was there, since 2000 when I started to code in JavaScript, and it was so simple that probably few developers thought about them! var o = { length:0, push:Array.prototype.push, toString:Array.prototype.join }; o.push(1,2,3); alert(o); // 1,2,3 arguments, in JavaScript, is an instanceof Object, and not an Array, as is in ActionScript since version 1.0 What we have done all this time, is to use Array.prototype methods injecting a basic object, with a simple length parameter, inside. If an object with a length value can be used as an Arra...