News for hackers. Stuff that matters.
Re:Javascript patterns by tracker1 on Wednesday January 01, 2014 @10:01PM (#6997955)
I happen to rely on function hoisting as well.. which each file being a module, I tend to define the module at the top, and have declarations below.

I also tend to prefer methods that accept an object parameter as opposed to using "this" and will often put wrappers on objects such as...

  Foo.prototype.bar = function(){ 
    Foo.bar.apply(null, p(arguments, this)); 
  }
with p being an alias to Array.prototype.shift.apply, put the second arg to the top of the former as an array... it's generally wrapped in a utility function... With that in place my entire prototype's functions are just pass through to static Foo.fn .. in general this makes it easier to test modules that are instance objects.

Though prefer to have utility modules over modules that expose an object constructor... Exception being Models, which inherit from EventEmitter2

Re:Javascript patterns by raganwald on Wednesday January 01, 2014 @10:09PM (#6997979)
We have a special on combinators this evening. Why not try a side order?

    function explicitize (fn) {
      return function () {
        return fn.apply(null, p(arguments, this));
      }
    }
Now you can write:

    foo.prototype.bar = explicitize(function (myself, something, etc) {
      // ...
    }
Re:Javascript patterns by tracker1 on Thursday January 02, 2014 @11:32AM (#7000395)
that's pretty much what I meant by wrapped in a utility function... generally... something akin to explitize(ConstructorName, 'methodname') .. so that the passthrough call(s) can be shimmed/mocked for testing...