Specifically, I don't understand why some methods require a .prototype
in front of them but others to not. I was practising a code where a correct answer was
var Foo = function(value) {
this.val = value;
}
Foo.prototype.valueOf = function() {
return this.val;
}
and I am wondering why the prototype in Foo.prototype.valueOf
was needed, why can you not simply just do Foo.valueOf
? It is what I did before with other prototypes. For example, I do x.slice(2,4)
and not x.prototype.slice(2,4).