Skip to content

Instantly share code, notes, and snippets.

View wentout's full-sized avatar
😎
building teleport

Viktor Vershanskiy wentout

😎
building teleport
View GitHub Profile
@wentout
wentout / Forkable.js
Last active December 7, 2020 20:17
forkable instance example
const Forkable = function () { };
Object.defineProperty(Forkable.prototype, 'fork', {
get () {
const me = this;
return function (...args) {
debugger;
// this keyword points to instance itself
if (new.target) {
return new me.constructor(...args);
@wentout
wentout / SuperIsACall.js
Last active December 7, 2020 18:08
not only the syntax sugar
const ogp = Object.getPrototypeOf;
const osp = Object.setPrototypeOf;
const supervise = (instance, args) => {
const seek4name = args.callee.name;
let current = instance;
do {
if (current === null) {
break;
}
@wentout
wentout / AnotherUnbind.js
Last active November 26, 2020 14:45
an example of Unbind via new keyword
'use strict';
function anotherBeBound () {
debugger;
this.b = this.a;
if (!new.target) {
return this;
}
};
anotherBeBound.prototype.a = 2;
@wentout
wentout / ConstOrLet.js
Last active October 27, 2020 22:27
const or let question
'use strict';
let toBeProp = 5;
const myObject = {};
Object.defineProperty(myObject, 'prop', {
get () {
return {
[Symbol.toPrimitive] () {
return toBeProp;
@wentout
wentout / FrozenPropExample.js
Last active October 21, 2020 09:21
Frozen Prop Example
'use strict';
const frozen = (() => {
return {
get propName () {
return 123;
}
};
})();
@wentout
wentout / ManifestateError.js
Created October 15, 2020 12:33
Error Manifestation Example
'use strict';
const GenerateError = function (error) {
if (!(error instanceof Error)) {
error = new Error('defaults');
}
debugger;
Object.setPrototypeOf(
@wentout
wentout / PrototypeChainDeepness.js
Created October 13, 2020 21:05
Prototype Chain Deepness test.
'use strict';
const MAX_NUM = 1000;
global.m = [];
global.start = Date.now();
global.current = {
name: 'root'
@wentout
wentout / IncrementalComputation_NumArrObj.js
Last active October 16, 2020 14:12
Example of Incremental Computation from Number to Array to Object
'use strict';
const ogp = Object.getPrototypeOf;
const myNumber = new Number(5);
const arr = new Array(1, 2, 3);
const example = {};
console.log(ogp(arr)); // Object(0) []
console.log(ogp(ogp(arr))); // [Object: null prototype] {}
@wentout
wentout / NumberFieldProfit.js
Last active September 26, 2020 20:36
example of what immutable number is indeed
const a = new Number(100);
a.subtract = function (b) {
return this.valueOf() - b;
};
console.log(a.subtract(10)); // 90
console.log(a - 10); // 90
console.log(a - 10); // 90
console.log(a - 10); // guess
@wentout
wentout / isArrowOrFunctionOrClass.js
Last active September 26, 2020 05:51
The answer to the question is something an Arrow or Class or regular Function
'use strict';
const myArrow = () => {};
const myFn = function () {};
class MyClass {};
const isArrowFunction = (fn) => {
if (typeof fn !== 'function') {
return false;