JSFiddle - React, Tailwind, and code Playground
by kentaromiura
JavaScript
var gene = Object.create(null);
gene.evolve = function(){
var evolution = Object.create(this);
evolution.ancestor = this;
return Object.create(evolution);
}
gene.clone = function(){
var ancestor = this.ancestor;
var evolution = Object.create(this);
evolution.ancestor = ancestor
var clone = Object.create(evolution);
// must copying the property because they are not enumerable on hasOwnProperty
for( var x in this ) if(Object.hasOwnProperty.call(this, x)) clone[x] = this[x];
return clone;
}
gene.isEvolutionOf = function(X){
return Object.isPrototypeOf.call(X, this)
}
var Brick = Object.create(gene)
console.log(Brick, Brick.isEvolutionOf(gene))
var Hash = gene.evolve();
Hash.forEach = function(f){
for( var x in this ) if(Object.hasOwnProperty.call(this, x)) f(x, this[x]);
}
var Map = Hash.evolve()
Map.foo = 'foo';
Map.forEach(function(x, v){console.log(x, v)})
console.dir(Map.clone())
console.log(Map.ancestor)
console.log(Map.isEvolutionOf(gene), Map.isEvolutionOf(Hash), Map.isEvolutionOf(Brick))