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 :: passing third parameter in context.commit vuejs 
Javascript :: Parsing the URL string using the Legacy API 
Javascript :: context 
Javascript :: javascript get object list by value 
Javascript :: react Dark/Light mode 
Javascript :: filtering to check that a string is contained in the object in js 
Javascript :: javascript create li element and append to ul 
Javascript :: cefsharp transparent background 
Javascript :: js Changing selected option by option id, class, or attribute 
Javascript :: restart my react -Dom 
Javascript :: function Using onpause and onplay Method to Start and Stop Animationto replace source file path to jpg image 
Javascript :: check if a number is multiple of 3 javascript 
Javascript :: how to check vowels in a string in javascript 
Javascript :: javascript python comparison 
Javascript :: create type in javascript 
Javascript :: express-roteamento 
Javascript :: remove a key/value mongo 
Javascript :: mongodb-nodejs-driver-deprecationwarning-collection-count-is-deprecated 
Javascript :: Remove special char 4m JS and Join 
Javascript :: devlop 
Javascript :: js destructure if exists 
Javascript :: web3 returns an object promise instead of number 
Javascript :: How to get access to the PromiseResult in React when calling Azure Cosmos DB api 
Javascript :: angularjs Re-evalute expressions when page reloads via history 
Javascript :: Issue in applying margin using angular "data-ng-style" 
Javascript :: React Native, <TextInput onChange{(text) = setState(text)} is returning an object instead of a string. Eventhough the default value is a String. Why 
Javascript :: What is the best way to download mulitple images using jquery 
Javascript :: restrict file input with react uploady 
Javascript :: debouce with clear debounce function javascript 
Javascript :: json array form to list object java 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =