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 / NamingConventionExample.js
Created August 5, 2022 09:11
Naming Convention Disambiguation on ChromeDevTools
const MethodName = 'MyMethodName';
var NamingObject = {
[MethodName]: function () {
this;
console.log(this.constructor.name); // MyMethodName
debugger;
}
};
@wentout
wentout / AssociatedMonoField.js
Last active July 23, 2022 06:02
monotonic types on field definitions and objects
let value = 123;
const MyGetSetTestClass = class {
get get() {
console.log('g0')
return function () {
console.log('g1')
return ++value;
}
@wentout
wentout / TheRing.js
Last active October 18, 2021 17:53
The Ring from Proxies
'use strict';
const a = { a: 1 };
const b = { b: 2 };
const c = { c: 3 };
const d = { d: 4 };
@wentout
wentout / DestructuringThisTest.js
Last active July 22, 2021 15:30
testing destructuring assignment `this` patterns
// By James M Snell @jasnell
// the first tweet:
// https://twitter.com/jasnell/status/1385464365046894599?s=20
class F {
a = 1;
b() {
return this.a;
}
@wentout
wentout / ProtoProxy.js
Last active February 13, 2021 11:00
demo for fields through prototype chain proxy declaration
'use strict';
const globalProto = Object.getPrototypeOf(Object.getPrototypeOf(Object));
const theirs = new Proxy(globalProto, {
get (target, prop, receiver) {
debugger;
console.log('p_get', prop);
},
set (target, prop, value, receiver) {
@wentout
wentout / MultiplicatorWith.js
Created January 15, 2021 08:32
An explanation of mixed type for Unknown Arity
'use strict';
const mul = (a) => {
const result = (b) => {
return mul(a * b);
};
result[Symbol.toPrimitive] = () => {
return a;
};
result.valueOf = () => {
@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;