How will we use the polyfill es6 class methods in ES5?
I am reading a book, and she says the following:
class Ninja {
constructor(name) {
this.name = name;
}
swingSword() {
return true;
}
}
coincides with
function Ninja(name) {
this.name = name;
}
Ninja.prototype.swingSword = function() {
return true;
};
I'm just asking why we add swingSword in the prototype, and not inside the constructor function?
Since the function should be on the object, and not on the prototype chain.
Am I right or wrong?
source
share