0 points

Javascript design patterns - Constructor pattern - Object - POO


dashboard

Wed Nov 04 2020 13:01:29 GMT+0000 (UTC)

Posted by @julien #javascript

// Using {} to create empty objects:
let person = {};
// Using Object() to create empty objects:
let person = new Object();
// Using function constructor:
function Person(name, age) {
  this.name = name;
  this.age = age;
  this.showName = () => console.log(this.name);
}
let person = new Person(‘Amy’, 28);
person.showName();
content_copy Copy

https://medium.com/javascript-in-plain-english/7-javascript-design-patterns-every-developer-should-know-df9c40e7debf