vongriffe
10/26/2017 - 10:12 AM

prototype

about prototype

function Animal(nameAnimal, roarAnimal) {
  this.name = nameAnimal;
  this.roar = roarAnimal;
}
Animal.prototype.getVoice = function() {
  console.log(this.roar);
}

// 
constructor
valueOf
toString 
isPrototypeOf 
propertyIsEnumerable
hasOwnProperty
toLocaleString
=
Object.prototype
//
// Kiedy tworzymy obiekt i nadajemy mu jakieś właściwoś
// ci i metody dostaje on również całą „paczkę” złożoną z właściwości i metod rodzica.

var Car = { type, km, color, drive, constructor valueOf,
            toString, isPrototypeOf, propertyisEnumer able,
            hasOwnProperty, toLovar Animal = {
type: "Invertebrates", getType: function() {
console.log(this.type); }
}
var fly = Object.create(Animal);
fly.getType(); // Invertebrates
var cat = Object.create(Animal, { name: {value: "Filemon"}, type: {value: "Vertebrata"},
});
cat.getType(); //Vertebrata
cat.name; // FilemoncaleStri