The extends keyword is used to create a child class of another class (parent). The child class inherits all the methods from another class. Inheritance is useful for code reusability: reuse properties and methods of an existing class when you create a new class.
Built-in classes like Array, Map and others are extendable also. Please note a very interesting thing. Built-in methods like filter , map and others – return new objects of exactly the inherited type PowerArray .
Array, Map, and other built-in classes are extendable. The most impressive thing is that built-in methods such as map , filter, and more - return new objects of literally the inherited type NumsArray .
Trying to get away with custom get/set functionality on ES6 Maps. Currently using Babel to transpile my code to ES5.
Chrome Version 41.0.2272.101 m
class MyMap extends Map {
get(key) {
if (!this.has(key)) { throw new Error(...); }
return super.get(key);
}
set(key) {
if (this.has(key)) { throw new Error(...); }
return super.set(key);
}
}
Not sure if I just got the syntax wrong or I'm missing an implementation of some sort. But I get the following error:
Method Map.prototype.forEach called on incompatible reciever
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