Nodejs Class Extend inherits(BaseClass)

Here you can find the source of inherits(BaseClass)

Method Source Code

Function.prototype.inherits = function (BaseClass) {
  function Surrogate () {}
  Surrogate.prototype = BaseClass.prototype;
  this.prototype = new Surrogate();
  this.prototype.constructor = this;
};

String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
};

Array.prototype.deepClone = function () {
  var arrClone = [];

  _.each(this, function(innerObj) {
    if (Array.isArray(innerObj)) {
      arrClone.push(innerObj.deepClone());
    } else {/*from  w  w w  . j  a v  a  2 s . c o  m*/
      arrClone.push(_.clone(innerObj));
    }
  });

  return arrClone;
};

Related

  1. subclass(base)
    Function.prototype.subclass = function(base) {
      var c = Function.prototype.subclass.nonconstructor;
      c.prototype = base.prototype;
      this.prototype = new c();
    };
    Function.prototype.subclass.nonconstructor = function() {};
    Object.size = function(obj) {
      var size = 0, key;
      for (key in obj) {
    ...
    
  2. inheritsFrom(parent)
    Function.prototype.inheritsFrom = function(parent){ 
      this.prototype = new parent();
      this.prototype.constructor = this;
      this.prototype.parent = parent.prototype;
      return this;
    };
    
  3. Inherits(parent)
    Function.prototype.Inherits = function(parent) {
      this.prototype = new parent();
      this.prototype.constructor = this;
      this.prototype.parent = parent.prototype;
    };
    
  4. inherit(ParentClass)
    Function.prototype.inherit = function(ParentClass) {
      this.prototype = Object.create(ParentClass.prototype);
      this.prototype.constructor = this;
      this.prototype.parent = ParentClass.prototype;
    
  5. __extends(parent)
    Function.prototype.__extends = function(parent) {
        this.prototype = Object.create(parent.prototype);
    };