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(); | |
| } |
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 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 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
| 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 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
| const MethodName = 'MyMethodName'; | |
| var NamingObject = { | |
| [MethodName]: function () { | |
| this; | |
| console.log(this.constructor.name); // MyMethodName | |
| debugger; | |
| } | |
| }; |
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
| let value = 123; | |
| const MyGetSetTestClass = class { | |
| get get() { | |
| console.log('g0') | |
| return function () { | |
| console.log('g1') | |
| return ++value; | |
| } |
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 a = { a: 1 }; | |
| const b = { b: 2 }; | |
| const c = { c: 3 }; | |
| const d = { d: 4 }; |
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
| // By James M Snell @jasnell | |
| // the first tweet: | |
| // https://twitter.com/jasnell/status/1385464365046894599?s=20 | |
| class F { | |
| a = 1; | |
| b() { | |
| return this.a; | |
| } |
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 globalProto = Object.getPrototypeOf(Object.getPrototypeOf(Object)); | |
| const theirs = new Proxy(globalProto, { | |
| get (target, prop, receiver) { | |
| debugger; | |
| console.log('p_get', prop); | |
| }, | |
| set (target, prop, value, receiver) { |
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 mul = (a) => { | |
| const result = (b) => { | |
| return mul(a * b); | |
| }; | |
| result[Symbol.toPrimitive] = () => { | |
| return a; | |
| }; | |
| result.valueOf = () => { |