Dan,

This is my last comment on the subject, as I foresee another endless
discussion, but:

Closure (Module Pattern) outperforms any other 'style' at least 2 to 1
on the test you quote, yet you recommend that we don't use it?

EdB



On Tue, Nov 27, 2012 at 5:22 PM, Daniel Wasilewski <devudes...@gmail.com> wrote:
> I'll try to help Alex :)
> But he may correct me if I am wrong.
>
>
> I believe this little test will show full picture and all 4 common styles of
> JS programming we are talking about here.
>
> Notice there is nothing about inheritance, just plain objects (classes)
> Once inheritance is involved things are slowing down with different ratios.
>
> http://jsperf.com/closures-vs-objects-vs-object-literals-vs-prototype/2
>
> Current proposed style of JS output is Object Literal (red bar in that
> test);
> Prototype (green bar) in plain object test seems to be 2nd solution
> outperformed by closure (blue bar) these days.
>
> But when inheritance is involved blue bar is getting shorter and prototype
> is catching up.
> Prototype pattern has also less footprint, since you adding 1 shared
> behaviour to your object that will be reused wherever possible instead
> creating brand new object.
>
> There is no surprise why Closure style runs very well on web kit based
> browsers since Google promoting this style and making optimisation just for
> it.
> FireFox trying to catch up, but Safari seems to do well both.
>
>
> Here is a little example of inheritance done with prototype pattern
>
> var Class = function(){}; //empty function to avoid invocation during
>
> Function.prototype.extend = function(C){
>   Class.prototype = C.prototype;
>   this.prototype = new Class();
>   this.prototype.constructor = this;
>   return this.prototype
> };
>
> now you can easily do this:
>
> function EventDispatcher(){}
> p = EventDispatcher.prototype;
>
> function DisplayObject(){
>     EventDispatcher.call(this); //equivalent of super
> }
> p = DisplayObject.extend(EventDispatcher);
>
> THis is obviously simplified form of what is really needed but it is good
> enough to cover lots of aspects already.
> Don't want to repeat what has been already sent here as examples, but
> simplicity and speed of this solution will outperform anything in
> real-project-use-case-scenario.
>
> Dan
>
>
> On 11/27/2012 8:06 AM, Erik de Bruin wrote:
>>
>> Alex,
>>
>> You keep referring to a "prototype". I might be missing something.
>> Where can I find it/how do I run it?
>>
>> EdB
>>
>>
>>
>> On Mon, Nov 26, 2012 at 10:32 PM, Alex Harui <aha...@adobe.com> wrote:
>>
>



-- 
Ix Multimedia Software

Jan Luykenstraat 27
3521 VB Utrecht

T. 06-51952295
I. www.ixsoftware.nl

Reply via email to