Can someone help me understand the difference between .prototype and regular instances in JavaScript? I am confused about why this code is not working and getting a type error: "undefined is not a function". I am experimenting with the Ninja() class and trying to compare it to .prototype and the first instance. Then I want to create a new instance of Ninja() called ninja and observe the differences.
function Ninja() {
this.swingSword = function() {
return true;
};
}
Ninja.prototype.swingSword = function() {
return false;
};
var ninja = new Ninja;
console.log(Ninja.prototype.swingSword());
console.log(Ninja.swingSword());
console.log(ninja.swingSword());
console.log(ninja.prototype.swingSword());