Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

weakset use cases javaScript

// Execute a callback on everything stored inside an object
function execRecursively(fn, subject, _refs = null){
  if(!_refs)
    _refs = new WeakSet();

  // Avoid infinite recursion
  if(_refs.has(subject))
    return;

  fn(subject);
  if("object" === typeof subject){
    _refs.add(subject);
    for(let key in subject)
      execRecursively(fn, subject[key], _refs);
  }
}

const foo = {
  foo: "Foo",
  bar: {
    bar: "Bar"
  }
};

foo.bar.baz = foo; // Circular reference!
execRecursively(obj => console.log(obj), foo);
Comment

PREVIOUS NEXT
Code Example
Javascript :: JavaScript combining rows of multiple datasets 
Javascript :: odoo owl usestate 
Javascript :: hacker news api react 
Javascript :: react button onclick components refined #1 
Javascript :: aboutreact axios 
Javascript :: check if function exists 
Javascript :: react button on child Content Data initialize 
Javascript :: nodejs express parse query params boolean 
Javascript :: React Native Component with Random Hexa 
Javascript :: remove nth character from string javascript 
Javascript :: how to iterate through linked list javascript 
Javascript :: generate qr codes js 
Javascript :: Html() is a JQuery Function 
Javascript :: Mirror Inverse Program in javascript 
Javascript :: convert snake case to camelcase javascript recursive 
Javascript :: knex js how to group by many items 
Javascript :: JS function examples 
Javascript :: javascript convert color string to rgb 
Javascript :: js create an object from another object with some keys removed 
Javascript :: jquery questions and answers 
Javascript :: javascript interview questions geeksforgeeks 
Javascript :: get 3 random items from array javascript 
Javascript :: phaser matter is undefined 
Javascript :: rest object javascript 
Javascript :: add function 
Javascript :: Hexo - Execute Console Commands 
Javascript :: js get data from liocalstorage 
Javascript :: javascript code to run colab in background 
Javascript :: Javascript shows me TypeError saying my variable is undefined 
Javascript :: trying to minimalize the js code and want to increase the performance speed in js 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =