Skip to content

Instantly share code, notes, and snippets.

@prof3ssorSt3v3
Created March 19, 2023 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prof3ssorSt3v3/98324bc895be33cfaa6e29c2eb308e14 to your computer and use it in GitHub Desktop.
Save prof3ssorSt3v3/98324bc895be33cfaa6e29c2eb308e14 to your computer and use it in GitHub Desktop.
Code from video about the new.target meta property
//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