Skip to content

Instantly share code, notes, and snippets.

@moisescastillo
Created July 19, 2020 21:05
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 moisescastillo/b2e2b9f558106d2a2771c867a1872899 to your computer and use it in GitHub Desktop.
Save moisescastillo/b2e2b9f558106d2a2771c867a1872899 to your computer and use it in GitHub Desktop.
Javascript object instances
function Person(name) {
this.name = name;
this.greeting = function() {
console.log(`Hi I'm ${this.name}`);
}
}
let person1 = new Person('Peter');
let person2 = new Person('Sarah');
console.log(person1.name);
// -> "Peter"
person1.greeting();
// -> "Hi I'm Peter"
console.log(person2.name);
// -> "Sarah"
person2.greeting();
// -> "Hi I'm Sarah"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment