From my perspective, prototypes work like this:
let Animal = function() {
this.bark = "woof";
}
Animal.prototype.barkLoud = function() {
return this.bark.toUpperCase();
}
let x = new Animal();
x.barkLoud() = "WOOF";
I fully understand the above explanation, but then I came across a tutorial that showed what seemed to be two different ways to assign prototypes to an object. Are these methods equivalent? If so, which one is preferable?
let obj = {
age: 45;
__proto__: Animal
}
vs
let obj = {
age: 45;
}
obj.prototype = Object.create(Animal.protoype);