lib/surround.js
function Surround(obj, pattern) {
  var self = this;

  var regEX = new RegExp(pattern);

  for(var fn in obj) {
    var orig = obj[fn];

    if (typeof(orig) != "function" || !regEX.test(fn))
      continue;

    // Already surrouneded.
    if (obj[fn].__stacks) {
      this.stacks = obj[fn].__stacks;
      return this;
    }

    this.stacks = this.defaults();

    // The replace of the original function.
    obj[fn] = function() {
      self.stacks.before
        .concat([orig], self.stacks.after)
        .forEach(function(fn) {
          fn.apply(obj, arguments);
        });
    };

    // Resets the stack and returns the basic func back.
    obj[fn].reset = function() {
      obj[fn] = orig;
      self.stacks = self.defaults();
    };

    // The stacks are cached in the func itself.
    obj[fn].__stacks = this.stacks;
  }
}
function Surround(obj, pattern) {
  var self = this;

  var regEX = new RegExp(pattern);

  for(var fn in obj) {
    var orig = obj[fn];

    if (typeof(orig) != "function" || !regEX.test(fn))
      continue;

    // Already surrouneded.
    if (obj[fn].__stacks) {
      this.stacks = obj[fn].__stacks;
      return this;
    }

    this.stacks = this.defaults();

    // The replace of the original function.
    obj[fn] = function() {
      self.stacks.before
        .concat([orig], self.stacks.after)
        .forEach(function(fn) {
          fn.apply(obj, arguments);
        });
    };

    // Resets the stack and returns the basic func back.
    obj[fn].reset = function() {
      obj[fn] = orig;
      self.stacks = self.defaults();
    };

    // The stacks are cached in the func itself.
    obj[fn].__stacks = this.stacks;
  }
}
function Surround ( obj , pattern ) { var self = this ; var regEX = new RegExp ( pattern ) ; for ( var fn in obj ) { var orig = obj [ fn ] ; if ( typeof ( orig ) != "function" || ! regEX . test ( fn ) ) continue ; // Already surrouneded. if ( obj [ fn ] . __stacks ) { this . stacks = obj [ fn ] . __stacks ; return this ; } this . stacks = this . defaults ( ) ; // The replace of the original function. obj [ fn ] = function ( ) { self . stacks . before . concat ( [ orig ] , self . stacks . after ) . forEach ( function ( fn ) { fn . apply ( obj , arguments ) ; } ) ; } ; // Resets the stack and returns the basic func back. obj [ fn ] . reset = function ( ) { obj [ fn ] = orig ; self . stacks = self . defaults ( ) ; } ; // The stacks are cached in the func itself. obj [ fn ] . __stacks = this . stacks ; } }
Surround constructor.

@param {Object} Object
@param {Pattern} pattern
@constructor
Surround constructor .