On Mon, 13 Dec 2010 05:21:53 +0100, Rick Waldron <[email protected]> wrote:

I agree with Garrett both in style and execution and I'd like to take his
example one step further...


var counter = new function() {

  var i = 0;

  this.next = function() {
    return ++i;
  };

  this.reset = function() {
    return (i = 0);
  };
};

Still seems like overkill to me, at least syntactically. How about just:
 var counter = function() {
   var i = 0;
   return {
     next : function () { return ++i; },
     reset: function () { return i = 0; }
   };
 }();

Pretty much the same operations, but I find it easier and more direct to read.

/L
--
Lasse R.H. Nielsen

_______________________________________________
JSMentors mailing list
[email protected]
http://jsmentors.com/mailman/listinfo/jsmentors_jsmentors.com

List Archive:
http://jsmentors.com/pipermail/jsmentors_jsmentors.com/

Reply via email to