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 / AwaitedAssign.js
Created April 7, 2025 13:52
Awaited Assign
'use strict';
const myObj = {};
let field = 123;
Object.defineProperty( myObj, 'field', {
async get () {
return new Promise( ( resolve, reject ) => {
setTimeout( () => {
resolve( field );
@wentout
wentout / Array.js
Created April 7, 2025 13:48
Struct Sizes Comparison
'use strict';
const count = 1_000_000_000;
console.time('finished in');
const myArr = [];
let i = 0;
@wentout
wentout / AwaitNew.ts
Created April 7, 2025 13:43
Native Await New
'use strict';
class MyPromise<T> extends Promise<T> {
constructor(handler: (
resolve: (value: T) => unknown,
reject: () => unknown) => void
) {
super(handler);
}
}
@wentout
wentout / PubSubOnWrappers.js
Last active March 8, 2025 00:02
Publisher Subscriber pattern made via Wrapper
'use strict';
// for testing this code please use the following command
//
// node PubSubOnWrappers.js | grep stack
//
// to see if stack size exceed
//
// for huge amount of async subs in Node.js we are receiving
// "Exception in PromiseRejectCallback"
@wentout
wentout / v8bug.js
Created August 15, 2024 13:45
new v8 version bug since node.js 22
'use strict';
// though Error.prototype.stack is non standard
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/stack
const myErrorObject = new Error('my error');
myErrorObject.prop = 123;
const hop = (o, p) => Object.prototype.hasOwnProperty.call(o, p);
@wentout
wentout / InstanceOfLies.js
Created March 12, 2024 11:34
improved Eric Elliott's instanceof lies example
function foo() { };
const bar = { a: 'a' };
Object
.setPrototypeOf(
foo.prototype,
bar
);
const baz = Object.create(foo.prototype);
console.log(baz instanceof foo);
@wentout
wentout / ArrayDotNotation_Habitable.js
Last active February 28, 2024 20:54
Array Dot Notation JS Example
'use strict';
const ogp = Object.getPrototypeOf;
const osp = Object.setPrototypeOf;
const MyArrayConstructor = function() {};
osp(MyArrayConstructor.prototype, new Array);
class MyArray extends MyArrayConstructor {
constructor(...args) {
super(...args);
@wentout
wentout / ClassInfinitLoop.js
Created February 8, 2024 11:00
Infinite Loops
class Base {
constructor() {
return new Extended;
}
}
class Extended extends Base {
constructor() {
super();
}
@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;
},