Posts

Showing posts from May, 2008

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!

[OT] Does Zend rely in its own program language?

During an interesting meeting at work, me and my colleagues talked, for some reason, about Zend, and its weird market strategy. What I mean, is that articles like this one , are daily present in our mind (we, as certified PHP developers :D) At the same time, today I though about one simple thing: Which program language is the diamond of MS? C# Which program language does MS use to create applications? C# Is MS IDE writen in C#, to develop in C#? Almost Which program language is the diamond of Sun Microsystem? Java Which program language does Sun use to create applications? Java Is Eclipse IDE written in Java, to develop in Java? Almost Same loop could be applied for Python, Ruby, D, Ocaml ... others, now stop one second ... Which program language is the diamond of Zend? PHP Which program language does Zend use to create applications? Java Is Zend IDE written in PHP (GTK), to develop in PHP? NO I know that phpgtk is a project out of the box , but it seems that Zend does not rely in its

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