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 / CallbackHellBindLuck.js
Last active June 25, 2025 00:10
Callback Hell Error-First Callback Convention .bind & .luck solution
'use strict';
/**
AI explanation from Qwen coder 2.5
In Node.js, the conventional way
to perform a null check in a callback function,
particularly for error handling,
involves checking the first argument of the callback.
@wentout
wentout / InstanceWhichIsBothCallableAndNewableFromItself.js
Last active June 24, 2025 23:59
all you need to know about Constructional Objects in JavaScript
'use strict';
const ogp = Object.getPrototypeOf;
const ohp = Object.prototype.hasOwnProperty;
const Cstr = function () {
// console.log(this.value);
const root = this;
const main = this.constructor;
const isItSelf = main === Cstr;
@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 / StructSizeComparison_Array.js
Last active April 10, 2025 11:52
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();
}