Posts

Showing posts with the label Stack

Lazy developers, Stack concept, and the fastest, unobtrusive, JavaScript StringBuilder

Fast Web, and lazy developers About 1 month ago, I have posted a little piece of code that, in some way, could be a little revolution for JavaScript 3rd edition, and every kind of library. I explained how to use native Array methods with an object, to extend Array itself, or simply create a Stack behaviour, compatible with every used browser. Few comments a part, in both Ajaxian and this site, it seems that nobody had enough fantasy to use that tricky piece of code to create every kind of Stack based constructor, library, or Iterator, without destroying the native Array.prototype. So, here I am, with another little piece of code that uses the same Stack concept to create a StringBuilder constructor. The Fastest Unobtrusive JavaScript StringBuilder A common problem with JavaScript and, specially, Internet Explorer, is string concatenation. You can find every kind of benchmark, even in IEBlog , about string concatenation problems. IE Team seems to suggest the usage of an Array, becaus...

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!

Stack and ArrayObject - How to create an advanced subclassed Array constructor

Another problem left to solve is that after subclassing an Array one would like the return types of Array.prototype methods to be of the subclass type instead of its superclass type Array. This comment is, basically, a summary of the reason I created the ArrayObject constructor . Today, I have totally rewrote that constructor, using a Stack instance as prototype. The Stack constructor aim is to subclass the Array one in the most compatible, and light, way. For this reason, I have not changed native Array behaviours, those that return an Array, for example, instead of a Stack instance (concat, filter, map, slice). But the good thing of Stack, is that now we can create our subclassed Array constructor, without affecting the native Array object, and adding, modifying, or removing, whatever we want. For example, to solve the problem described on top of this post, I have simply modified inherited Stack methods, returning an instance of ArrayObject , every time we use, for example, a conca...

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