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 / ClassInstancePrototypeChainTest.js
Created January 12, 2023 16:48
Ptototype Inheritance just is not the same for Class instances not
class A {
a = 1
constructor() {
console.log('A constructor this.a : ', this.a);
this.a = 1;
console.log('A constructor this.a : ', this.a);
}
}
class B extends A {
@wentout
wentout / FunctionalInheritance.ts
Last active January 12, 2023 14:07
TypeScript Functional Inheritance with Prototypes working
const MyConstructor: IMyConstructor = function (this: MyConstructorInstance, name: string) {
this.name = name;
} as IMyConstructor;
MyConstructor.prototype.name = 'default';
MyConstructor.prototype._char = 'default';
Object.defineProperty(MyConstructor.prototype, 'char', {
get(this: MyConstructorInstance) {
return this._char;
},
@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;
}