Following is my Class, Its prototype vale is not getting changed, (I am working on the Chrome console)
class Rectangle {
constructor(length, width) {
this.length = length;
this.width = width;
}
getArea() {
return this.length * this.width;
}
static create(length, width) {
return new Rectangle(length, width);
}
}
and I am Changing the prototype of the Class to null
Rectangle.prototype= null
When I try to access the changed Prototype, the value remains the same "Object" with 'getArea' prototype property of Rectangle
But in ES5 the prototype value is changed.
In ES6, the .prototype
property of class
es is not writable and not configurable1. Use strict mode where you do the assignment and you'll get ReferenceError
exception "Invalid assignment in strict mode".
If you want to overwrite the (which is a very bad idea in general), .prototype
you'll have to use Object.defineProperty(Rectangle, "prototype", {value: …})
.
1: See §14.5.14 ClassDefinitionEvaluation, step 16: Perform MakeConstructor(F, writablePrototype=false, prototype=proto).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With