Skip to content

Instantly share code, notes, and snippets.

@wentout
Last active August 17, 2020 16:04
Show Gist options
  • Select an option

  • Save wentout/c2b207400a3e2c0aa99bbfb29508a333 to your computer and use it in GitHub Desktop.

Select an option

Save wentout/c2b207400a3e2c0aa99bbfb29508a333 to your computer and use it in GitHub Desktop.
An Example how an Object might be derived from new Number
const DerivedPrimitiveFactory = function (existentInstance, ModificatorType) {
const TripleSchemeClosure = function () {
ModificatorType.prototype = this;
ModificatorType.prototype.constructor = ModificatorType;
return ModificatorType;
};
TripleSchemeClosure.prototype = existentInstance;
TripleSchemeClosure.prototype.constructor = existentInstance.constructor;
return new TripleSchemeClosure();
};
const NUMBER_4_DERIVATION = new Number(5);
const DerivationConstructor = function () {
this.description = 'derived from number';
};
const DerivativeConstructor = DerivedPrimitiveFactory(NUMBER_4_DERIVATION, DerivationConstructor);
const derivative = new DerivativeConstructor();
console.log('derivative.description :', derivative.description);
console.log('derivative.constructor.name :', derivative.constructor.name);
const proto_proto = Object.getPrototypeOf(Object.getPrototypeOf(derivative));
console.log('derivative.__proto__.__proto__ :', proto_proto.constructor.name);
console.log('derivative.__proto__.__proto__.valueOf() :', proto_proto.valueOf());
console.log('derivative.valueOf() :', derivative);
console.log('derivative instanceof DerivativeConstructor :',
derivative instanceof DerivativeConstructor);
console.log('derivative instanceof DerivationConstructor :',
derivative instanceof DerivationConstructor);
console.log('derivative instanceof Number :',
derivative instanceof Number);
debugger;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment