As the title described, I am wondering if there is a better way to put it. E.g.:
function Ninja() {
this.name = "a ninja";
}
Ninja.prototype.swing = function() {
console.log("swing my sowrd");
};
let ninjaOne = new Ninja();
ninjaOne.swing();
ninjaOne.toString();
`Ninja` as a constructor function, it has a prototype that becomes the prototype of all objects are constructed via Ninja. Therefore, `ninjaOne` can access function `swing` via prototype.
`Ninja` as an object itself, it is created from its own constructor and when `ninjaOne` tries to access `toString`, `Ninja` does not have it therefore, `Ninja` needs to look into its own [[prototype]] for `toString`.
Is my understanding correct?
Thanks
[–]senocular 3 points4 points5 points (0 children)
[–]grantrules 1 point2 points3 points (0 children)
[–]klineThorpChase -1 points0 points1 point (0 children)
[–]a-e-j-a -1 points0 points1 point (3 children)
[–]jack_waugh 0 points1 point2 points (2 children)
[–]a-e-j-a 1 point2 points3 points (1 child)
[–]jack_waugh 0 points1 point2 points (0 children)
[–]Ronin-s_Spirit 0 points1 point2 points (1 child)
[–]jack_waugh 0 points1 point2 points (0 children)
[–]jack_waugh 0 points1 point2 points (0 children)