Skip to content

Instantly share code, notes, and snippets.

@digitalconceptvisuals
Created July 29, 2020 15:29
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 digitalconceptvisuals/24e7e32dbd4c6e4936de536f192f6360 to your computer and use it in GitHub Desktop.
Save digitalconceptvisuals/24e7e32dbd4c6e4936de536f192f6360 to your computer and use it in GitHub Desktop.
// Constructor function
// Not to be used as normal function
function Person(id, name) {
// Was this called using new?
if (!new.target)
throw "Error: use 'new Person()'";
this.id = id;
this.name = name;
}
// Expect error here
let result = Person(1, "Brendan");
----------------------------------
Output
----------------------------------
throw "Error: use 'new Person()'";
^
Error: use 'new Person()'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment