Learn more  » Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

skava / exotic   js

Repository URL to install this package:

Version: 2.0.8 

/ src / types / NATIVE / prototype / extend.ts

// @todo
var isNull = x => x === null

var getPrototypeProp = x => x.prototype
var getProto = Object.getPrototypeOf || getPrototypeProp

// GrandChild, Child, Parent
var createFallback = Parent => {
  console.log({ Parent })
  return getProto(Parent)
  // return new GrandChild()
}
var create = (Child, Parent) => {
  return isNull(Child) ? Object.create(Child) : createFallback(Child, Parent)
}

const FROZEN_EMPTY_ARRAY = Object.freeze([])

var extendWhenArray =
  { __proto__: FROZEN_EMPTY_ARRAY } instanceof Array &&
  function(Parent, Child) {
    // eslint-disable-next-line
    Child.__proto__ = Parent
  }

// eslint-disable-next-line func-style
var extendForIn = (Child, Parent) => {
  // eslint-disable-next-line
  for (var prop in Parent) {
    // eslint-disable-next-line
    if (Parent.hasOwnProperty(prop)) {
      Child[prop] = Parent[prop]
    }
  }
}

var assignPrototype = (Child, Parent) => (Child.prototype = create(Parent))

var extendStatics = Object.setPrototypeOf || extendWhenArray || extendForIn

var __extends = (function() {
  // actual __extends
  return function(Child, Parent) {
    extendStatics(Child, Parent)
    function GrandChild() {
      this.constructor = Child
    }
    Child.prototype = isNull(Parent)
      ? Object.create(Parent)
      : (assignPrototype(GrandChild, Parent), new GrandChild())

    return GrandChild
  }
})()

function factory(Parent, fn) {
  const finish = Child => __extends(Child, Parent)
  const builder = cb => cb(finish)
  if (!fn) return builder
  return builder(fn)
}

factory.factory = factory
factory.__extends = __extends

module.exports = factory