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; | |
} |
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 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 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 = () => { |
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 Forkable = function () { }; | |
Object.defineProperty(Forkable.prototype, 'fork', { | |
get () { | |
const me = this; | |
return function (...args) { | |
debugger; | |
// this keyword points to instance itself | |
if (new.target) { | |
return new me.constructor(...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
const ogp = Object.getPrototypeOf; | |
const osp = Object.setPrototypeOf; | |
const supervise = (instance, args) => { | |
const seek4name = args.callee.name; | |
let current = instance; | |
do { | |
if (current === null) { | |
break; | |
} |
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'; | |
function anotherBeBound () { | |
debugger; | |
this.b = this.a; | |
if (!new.target) { | |
return this; | |
} | |
}; | |
anotherBeBound.prototype.a = 2; |
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'; | |
let toBeProp = 5; | |
const myObject = {}; | |
Object.defineProperty(myObject, 'prop', { | |
get () { | |
return { | |
[Symbol.toPrimitive] () { | |
return toBeProp; |