Skip to content

Instantly share code, notes, and snippets.

@PavanKu
Created December 26, 2017 05:37
Show Gist options
  • Save PavanKu/a001281893278f58edac9adb73b2a81f to your computer and use it in GitHub Desktop.
Save PavanKu/a001281893278f58edac9adb73b2a81f to your computer and use it in GitHub Desktop.
this in Constructor method
function Person(fn, ln) {
this.first_name = fn;
this.last_name = ln;
this.displayName = function() {
console.log(`Name: ${this.first_name} ${this.last_name}`);
}
}
let person = new Person("John", "Reed");
person.displayName(); // Prints Name: John Reed
let person2 = new Person("Paul", "Adams");
person2.displayName(); // Prints Name: Paul Adams
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment