Skip to content

Instantly share code, notes, and snippets.

@DanElliottPalmer
Last active August 29, 2015 14:17
Show Gist options
  • Save DanElliottPalmer/aa22a3c038d5f2ef94d2 to your computer and use it in GitHub Desktop.
Save DanElliottPalmer/aa22a3c038d5f2ef94d2 to your computer and use it in GitHub Desktop.
ES6 Map inheritance
/**
* I can do this
*/
function AwesomeArray(){
Array.call( this );
}
AwesomeArray.prototype = Object.create(Array.prototype);
var awesomeness = new AwesomeArray();
awesomeness.push("example");
console.log( awesomeness );
/**
* I cannot do this :(
*/
function NotAwesomeMap(){
Map.call( this );
}
NotAwesomeMap.prototype = Object.create(Map.prototype);
var notawesomeness = new NotAwesomeMap();
notawesomeness.set( "Example2", true );
/**
* TypeError: set method called on incompatible Object
*/
console.log( notawesomeness );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment