I learned about prototype and proto and i think i understand it but this just doesn't make sense? Can somebody explain to me why accessing directly Object like this doesn't work.
function createObj() {
this.name = 'user';
this.prezime = 'user';
}
var obj1 = new createObj();
createObj.prototype.__proto__.toString = function () {
return 'works';
} //obj1.toString() returns 'works'
createObj.__proto__.__proto__.toString = function () {
return 'this works as well';
} //obj1.toString() returns 'this works as well '
//Then why this doesn't work:
Object.toString = function () {
return true;
}
From my understanding I am directly changing Object object
.
So when I do obj1.toString()
shouldn't it go to prototype
and
then proto
inside prototype
and find toString()
like it does from last two examples?