create a map without hardcoding the class name Map - Javascript Object

Javascript examples for Object:Object Method

Description

create a map without hardcoding the class name Map

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width"> 
   </head> 
   <body> 
      <script>
function createClass(arg) {//from   w  w w .  jav  a  2s.co  m
  if(arg.isArray){
    return [];
  }
  if(arg.has){
     return new Map();
  }
    return Object.create(Object.getPrototypeOf(arg));
}
console.log(createClass({}));

      </script>  
   </body>
</html>

Related Tutorials