plugin.js
function Plugin(square, collection) {
  if (!(this instanceof Plugin)) return new Plugin(square, collection);
  if (!square) throw new Error('Missing square instance');
  if (!collection) throw new Error('Missing collection');

  var self = this;

  this.square = square;           // Reference to the current square instance.
  this.async = async;             // Handle async operation.
  this._ = _;                     // Utilities.
  this.logger = {};               // Our logging utility.
  this.collection = collection;   // Reference to the original collection.

  // Provide a default namespace to the logging method, we are going to prefix
  // it with the plugin's name which will help with the debug ability of this
  // module.
  Object.keys(square.logger.levels).forEach(function generate(level) {
    self.logger[level] = square.logger[level].bind(
        square.logger
      , '[plugin::'+ self.id +']'
    );
  });

  // Merge the given collection with the plugin, but don't override the default
  // values.
  Object.keys(collection).forEach(function each(key) {
    self[key] = collection[key];
  });

  // Force an async nature of the plugin interface, this also allows us to
  // attach or listen to methods after we have constructed the plugin.
  process.nextTick(this.configure.bind(this));
}
function Plugin(square, collection) {
  if (!(this instanceof Plugin)) return new Plugin(square, collection);
  if (!square) throw new Error('Missing square instance');
  if (!collection) throw new Error('Missing collection');

  var self = this;

  this.square = square;           // Reference to the current square instance.
  this.async = async;             // Handle async operation.
  this._ = _;                     // Utilities.
  this.logger = {};               // Our logging utility.
  this.collection = collection;   // Reference to the original collection.

  // Provide a default namespace to the logging method, we are going to prefix
  // it with the plugin's name which will help with the debug ability of this
  // module.
  Object.keys(square.logger.levels).forEach(function generate(level) {
    self.logger[level] = square.logger[level].bind(
        square.logger
      , '[plugin::'+ self.id +']'
    );
  });

  // Merge the given collection with the plugin, but don't override the default
  // values.
  Object.keys(collection).forEach(function each(key) {
    self[key] = collection[key];
  });

  // Force an async nature of the plugin interface, this also allows us to
  // attach or listen to methods after we have constructed the plugin.
  process.nextTick(this.configure.bind(this));
}
function Plugin ( square , collection ) { if ( ! ( this instanceof Plugin ) ) return new Plugin ( square , collection ) ; if ( ! square ) throw new Error ( 'Missing square instance' ) ; if ( ! collection ) throw new Error ( 'Missing collection' ) ; var self = this ; this . square = square ; // Reference to the current square instance. this . async = async ; // Handle async operation. this . _ = _ ; // Utilities. this . logger = { } ; // Our logging utility. this . collection = collection ; // Reference to the original collection. // Provide a default namespace to the logging method, we are going to prefix // it with the plugin's name which will help with the debug ability of this // module. Object . keys ( square . logger . levels ) . forEach ( function generate ( level ) { self . logger [ level ] = square . logger [ level ] . bind ( square . logger , '[plugin::' + self . id + ']' ) ; } ) ; // Merge the given collection with the plugin, but don't override the default // values. Object . keys ( collection ) . forEach ( function each ( key ) { self [ key ] = collection [ key ] ; } ) ; // Force an async nature of the plugin interface, this also allows us to // attach or listen to methods after we have constructed the plugin. process . nextTick ( this . configure . bind ( this ) ) ; }
Plugin interface for square.

@constructor
@param {Square} square
@param {Object} collection
@api public
Plugin interface for square .