-
-
Save domenic/c1566e755c9e14613aa1 to your computer and use it in GitHub Desktop.
ES2015 constructor call trick
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 returnMe; | |
class HTMLElement { | |
constructor() { | |
if (returnMe) { | |
const temp = returnMe; | |
returnMe = null; | |
return temp; | |
} | |
// ... | |
return allocateFromUACode(); | |
} | |
} | |
class XFoo extends HTMLElement { | |
constructor() { | |
super(); // effectively does this = returnMe | |
} | |
} | |
function upgradeEl(el) { | |
returnMe = el; | |
new XFoo(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem: