Skip to content

Instantly share code, notes, and snippets.

@bernar83
Created October 26, 2017 21:09
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 bernar83/c128beed42015440fa7094bfe78712bf to your computer and use it in GitHub Desktop.
Save bernar83/c128beed42015440fa7094bfe78712bf to your computer and use it in GitHub Desktop.
function setName(name) {
this.name = name;
}
const person1 = {
setName: setName
};
const person2 = {};
person1.setName('bob');
console.log(person1.name); // "bob"
person1.setName.call(person2, 'bill');
console.log(person2.name); // "bill"
const dave = new person1.setName('dave');
console.log(dave.name); // "dave"
console.log(person1.name); // "bob"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment