Why I prefer my own 'new Map()' based createObjects() function over 'new Map()' *.set().
Aad Pouw

Aad Pouw @aadswebdesign

About: 25+, retired and living in a tropical country. There I enjoy life and when time left I spend some time on webdesign.

Location:
The Hague/Netherlands
Joined:
May 21, 2020

Why I prefer my own 'new Map()' based createObjects() function over 'new Map()' *.set().

Publish Date: Jan 25
0 0

It's about, why I prefer this function over using 'new Map()' *.set()?
First the code:

export async function createObjects(...args){
  const [map_object = null, map_entries = null] = args;
  if(map_object !== null && map_entries !== null){
    const map = new Map([[map_object,map_entries]]);
    return map.get(map_object);
  }
  return null;
};
Enter fullscreen mode Exit fullscreen mode

The advances of this function over using
*.set('key1', 'value1');
*.set('key2', 'value2');

It can be used in the same way as using an ordinary object structure, doing the same thing as 'set' and is much shorter;

  const foo = {key1: val1,key2: val2,};
  const bar = await FT.createObjects('bar_obj',{key1: val1,key2: val2,});
Enter fullscreen mode Exit fullscreen mode

or

  const foo = {};
  foo.key1 = val1;
  foo.key2 = val2;

  // 'FT' is a namespace and is from 'import * as FT from "...js"'!
  const bar = await FT.createObjects('bar_obj',{});
  bar.key1 = val1;
  bar.key2 = val2;

  bar['key1'] = val1;
  bar['key2'] = val2;
Enter fullscreen mode Exit fullscreen mode

Note:

It's used in:
My recently created '*ModuleEditer' and wherover more at a later stage.

My present rebuild of my github page and wherover more at a later stage too.

  • Also, I do this rebuild on my localhost and I will replace my present GH page, when the time is right for it.

That's it!

Comments 0 total

    Add comment