This file contains 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 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 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 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 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 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 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 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(); | |
} |
This file contains 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 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 { |
This file contains 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
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; | |
}, |
NewerOlder