Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

insert property to many object with prototype

class Dog {
  constructor(name) {
    this.name = name;
  }

  bark() {
    return `Woof!`;
  }
}

const dog1 = new Dog("Daisy");
const dog2 = new Dog("Max");
const dog3 = new Dog("Spot");

Dog.prototype.play = () => console.log("Playing now!");

dog1.play();
Source by www.patterns.dev #
 
PREVIOUS NEXT
Tagged: #insert #property #object #prototype
ADD COMMENT
Topic
Name
6+3 =