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