Horje
Using DOM Nodes As Keys Code Example
Using DOM Nodes As Keys
<span id="thing" class="thing">a thing.</span>

<script>
const myWeakMap = new WeakMap();

// Set a value to a specific node reference.
myWeakMap.set(document.getElementById('thing'), 'some value');

// Access that value by passing the same reference.
console.log(myWeakMap.get(document.querySelector('.thing')); // 'some value'
</script>
Source: macarthur.me
Using DOM Nodes As Keys
<span id="el1">first element</span>
<span id="el2">second element</span>

<script>
  const someObj = {
    [document.getElementById('el1')]: 'some value'
  };

  console.log(someObj[document.getElementById('el1')]);
  // 'some value'
</script>
Source: macarthur.me




Javascript

Related
super slider js Code Example super slider js Code Example
onsubmit  in js Code Example onsubmit in js Code Example
passing function inside a const react js Code Example passing function inside a const react js Code Example
how to include build script in node js Code Example how to include build script in node js Code Example
git reset local branch to origin Code Example git reset local branch to origin Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9