Created
March 19, 2023 18:32
-
-
Save prof3ssorSt3v3/98324bc895be33cfaa6e29c2eb308e14 to your computer and use it in GitHub Desktop.
Code from video about the new.target meta property
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
//new.target meta property | |
function Being() { | |
// | |
console.log(new.target); | |
if (new.target === undefined) throw new TypeError('Missing new'); | |
if (!new.target) throw new TypeError('Missing new'); | |
console.log(typeof new.target); //function | |
console.log(new.target.name); // Being | |
console.log(this); | |
} | |
class Human extends Being { | |
constructor() { | |
super(); | |
console.log(new.target); | |
//this | |
} | |
} | |
let xenomorph = () => { | |
//arrow functions cannot be called with new (as constructor) | |
console.log(this); | |
}; | |
function Alien() { | |
//console.log(new.target); | |
} | |
// Being(); | |
try { | |
// new Being(); | |
new xenomorph(); | |
} catch (err) { | |
console.log(err.name, err.message); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment