Files!
/**
* @fileOverview Cors Middleware.
*/
var util = require('util');
var fs = require('fs');
var Promise = require('bluebird');
var _ = require('lodash');
var Middleware = require('./middleware');
var helpers = require('../util/helpers');
/**
* The Cors Middleware.
*
*/
var Cors = module.exports = {};
/**
* CORS Middleware
*
* @param {Object} req The request Object.
* @param {Object} res The response Object.
* @param {Function(Error=)} next pass ctrl.
*/
Cors.use = function(req, res, next) { ... };
Module Description
Dependencies
System Deps
NPM Deps
Project Deps
Export Statement
Method Definition
DocBlocks for Args
Function Expression
@thanpolas
/**
* @fileOverview Cors Middleware.
*/
var util = require('util');
var fs = require('fs');
var Promise = require('bluebird');
var _ = require('lodash');
var Middleware = require('./middleware');
var helpers = require('../util/helpers');
1.
2.
3.
var Cors = module.exports = function(){
Middleware.apply(this, arguments);
};
util.inherits(Cors, Middleware);
var Cors = module.exports = {};
/**
* The Cors Middleware.
*
* @contructor
* @extends {cc.Middleware}
*/
var Cors = module.exports = function(){
Middleware.apply(this, arguments);
};
util.inherits(Cors, Middleware);
/**
* CORS Middleware
*
* @param {Object} req The request Object.
* @param {Object} res The response Object.
* @param {Function(Error=)} next pass ctrl.
*/
Cors.prototype.allowCrossDomain = function(req, res, next) {...};
/**
* The Cors Middleware.
*
*/
var Cors = module.exports = {};
/**
* CORS Middleware
*
* @param {Object} req The request Object.
* @param {Object} res The response Object.
* @param {Function(Error=)} next pass ctrl.
*/
Cors.use = function(req, res, next) { ... };
var util = require('util');
var EventEmitter = require('events').EventEmitter;
var MiddlewareBase = module.exports = function() {
EventEmitter.apply(this, arguments);
this.foo = 1;
};
util.inherits(MiddlewareBase, EventEmitter);
middleware-base.midd.js
var util = require('util');
var MiddleWareBase = require('./middleware-base.midd');
var Cors = module.exports = function() {
MiddlewareBase.apply(this, arguments);
console.log(this.foo); // 1
};
util.inherits(Cors, MiddlewareBase);
cors.midd.js
Cors.prototype.use = function(req, res, next) {
// good
doSomeAsync(this._handleAsync.bind(this));
// bad
doSomeAsync(this._handleAsync);
};
Cors.prototype.use = function(req, res, next) {
while(true) { // highly repetitive operation
// good
var self = this;
doSomeAsync(function(result) {
self._handleAsync(result);
});
// bad
doSomeAsync(this._handleAsync.bind(this));
}
};
var util = require('util');
var EventEmitter = require('events').EventEmitter;
var MiddlewareBase = module.exports = function() {
EventEmitter.apply(this, arguments);
this.foo = 1;
};
util.inherits(MiddlewareBase, EventEmitter);
Base Constructors vanilla
var EventEmitter = require('events').EventEmitter;
var cip = require('cip');
var CeventEmitter = cip.cast(EventEmitter);
module.exports = CeventEmitter.extend();
Base Constructors using CIP
var util = require('util');
var MiddleWareBase = require('./middleware-base.midd');
var Cors = module.exports = function() {
MiddlewareBase.apply(this, arguments);
console.log(this.foo); // 1
};
util.inherits(Cors, MiddlewareBase);
Child Constructors vanilla
var MiddlewareBase = require('./middleware-base.midd');
var Cors = module.exports = MiddlewareBase.extend(function () {
/* Ctor */
});
Child Constructors using CIP
var MiddlewareBase = require('./middleware-base.midd');
var MiddlewareTraits = require('./middleware-traits.midd');
var Cors = module.exports = MiddlewareBase.extend(function () {
/* Ctor */
});
Cors.mixin(MiddlewareTraits);
Mixins!
var Cors = require('./cors.midd');
var SuperCors = module.exports = Cors.extend(function () {
/* Ctor */
});
Inheritance Goes on...
Thank you
(here is where you applaud)
Thanasis Polychronakis
@thanpolas
Questions?
Thanasis Polychronakis
@thanpolas