“Prototypy obiektów JavaScript” Kod odpowiedzi

Prototyp funkcji JavaScript

function Person(name) {
  this.name = name;
}
Person.prototype.getName = function() {
  return this.name;
}

var person = new Person("John Doe");
person.getName() //"John Doe"
TC5550

Prototypy obiektów JavaScript

function Person(first, last, age, eyecolor) {
  this.firstName = first;
  this.lastName = last;
  this.age = age;
  this.eyeColor = eyecolor;
}

const myFather = new Person("John", "Doe", 50, "blue");
const myMother = new Person("Sally", "Rally", 48, "green");
naly moslih

Odpowiedzi podobne do “Prototypy obiektów JavaScript”

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu