This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const myObj = {}; | |
let field = 123; | |
Object.defineProperty( myObj, 'field', { | |
async get () { | |
return new Promise( ( resolve, reject ) => { | |
setTimeout( () => { | |
resolve( field ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const count = 1_000_000_000; | |
console.time('finished in'); | |
const myArr = []; | |
let i = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
class MyPromise<T> extends Promise<T> { | |
constructor(handler: ( | |
resolve: (value: T) => unknown, | |
reject: () => unknown) => void | |
) { | |
super(handler); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function foo() { }; | |
const bar = { a: 'a' }; | |
Object | |
.setPrototypeOf( | |
foo.prototype, | |
bar | |
); | |
const baz = Object.create(foo.prototype); | |
console.log(baz instanceof foo); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Base { | |
constructor() { | |
return new Extended; | |
} | |
} | |
class Extended extends Base { | |
constructor() { | |
super(); | |
} |
NewerOlder