Last active
August 29, 2015 14:17
-
-
Save DanElliottPalmer/aa22a3c038d5f2ef94d2 to your computer and use it in GitHub Desktop.
ES6 Map inheritance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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