>
> but it seems thats better for closure
> http://jsperf.com/prototypemodule-vs-closuremodule/11
>


If i run http://jsperf.com/prototypemodule-vs-closuremodule/11 a couple of
times, even though speed of closure and prototype version are close to each
other, closure most often ends up being slightly faster.


@ // ravi
So basically i get the same stuff with closure, that i get with prototype
and at same speed, right?
=> but without the need for *"new"* and *"prototype"*

I'm kind of still relying on *"this"*, but if i want to use private scope,
afaik,
prototype methods wont help me anyway and i need to use the same style i
used with the closure style before,
for example:

    function Car(name, cost, mpg, alternative) {      var _x = 5;
      this.getX = function () { return _x; };
      this.name = name;
      this.cost = cost;
      this.env_damage = mpg;
      this.alternative = alternative;
    }
    (new Car()).getX();


vs.

    function closureCar(name, cost, mpg, alternative) {          var _x = 5;
          return {            getX: function () { return _x; },
            name: name,
            cost: cost,
            env_damage: mpg,
            alternative: alternative
          };
    }
    closureCar().getX();


I still have a strong feeling, that the closureCar, which doesnt use *"new"*
and doesnt use *"prototype"* is far easier to understand.
Sad thing is, that it seems to not be possible to get rid of *"this"*
without some negative performance implications :-/

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/CAN5%2BLUsTFD%3Dm67xT9x5ngqU-aNMDwifczaDGDBszFhKA4z3fgw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to