Nodejs Class Extend extend(obj)

Here you can find the source of extend(obj)

Method Source Code

// Object//from  w ww.j av a  2s . c o m
Object.prototype.extend = function(obj) {
   for (var i in obj) {
      if (obj.hasOwnProperty(i)) {
         this[i] = obj[i];
      }
   }
};

// Array
Array.prototype.first = function() {
    return this.length && this[0];
};

// Element
Element.prototype.remove = function() {
    this.parentElement.removeChild(this);
};
Element.prototype.find = function(id) {
    var result = null;
    for (var i = this.children.length - 1; i >= 0 && !result; i--) {
      if ( this.children[i].id === id ) {
        result = this.children[i];
      }
      else {
        result = this.children[i].find(id);
      }
    }
    return result;
};

Related

  1. __extends(superClass)
    Function.prototype.__extends = function(superClass) { 
        this.prototype = Object.create(superClass.prototype);
    }; 
    Object._entries = function(obj) {
        var entry = [];
        for (key in obj)
            entry[entry.length] = [key, obj[key]];
        return entry;
    };
    ...
    
  2. Inherits(parent)
    Object.prototype.Inherits = function(parent) {
      if(arguments.length > 1) {
        parent.apply(this, Array.prototype.slice.call(arguments, 1) );
      } else {      
        parent.call(this);
    };
    
  3. extend()
    Object.prototype.extend = function(){
       var Obj = function(){};
       Obj.prototype = this;
       return new Obj();
    
  4. extend(destination, source)
    Object.extend = function(destination, source) {
      for (var property in source) {
        if (source.hasOwnProperty(property)) {
          destination[property] = source[property];
      return destination;
    };
    
  5. extend(destination, source)
    Object.extend = function(destination, source) {
      for (var property in source) {
        if (source.hasOwnProperty(property)) {
          destination[property] = source[property];
      return destination;
    
  6. extend(object)
    Object.prototype.extend = function (object)
      var combined = this;
      object.each( function (value, key)
        combined[key] = value;
      });
      return combined;
    };
    ...
    
  7. extend(other)
    Object.prototype.extend = function(other)
      let property;
      for (property in other)
        if( other.hasOwnProperty(property) &&
            other[property] != null )
          this[property] = other[property];
    ...
    
  8. extend(target)
    Object.extend = function(target) {
        Array.toArray(arguments, 1).forEach(function(source) {
            var fld;
            for (fld in source) {
                if (source.hasOwnProperty(fld)) {
                    target[fld] = source[fld];
        });
    ...