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; | |
}, |
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 MethodName = 'MyMethodName'; | |
var NamingObject = { | |
[MethodName]: function () { | |
this; | |
console.log(this.constructor.name); // MyMethodName | |
debugger; | |
} | |
}; |
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
let value = 123; | |
const MyGetSetTestClass = class { | |
get get() { | |
console.log('g0') | |
return function () { | |
console.log('g1') | |
return ++value; | |
} |
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 a = { a: 1 }; | |
const b = { b: 2 }; | |
const c = { c: 3 }; | |
const d = { d: 4 }; |
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
// By James M Snell @jasnell | |
// the first tweet: | |
// https://twitter.com/jasnell/status/1385464365046894599?s=20 | |
class F { | |
a = 1; | |
b() { | |
return this.a; | |
} |
NewerOlder