Javascript / Chrome - How to copy an object from the webkit inspector as code

后端 未结 11 1917
天涯浪人
天涯浪人 2020-11-29 14:47

I am doing a console.log statement in my javascript in order to log a javascript object. I\'m wondering if there\'s a way, once that\'s done - to copy that object as javascr

11条回答
  •  抹茶落季
    2020-11-29 15:08

    This should help stringify deep objects by leaving out recursive Window and Node objects.

    function stringifyObject(e) {
      const obj = {};
      for (let k in e) {
        obj[k] = e[k];
      }
    
      return JSON.stringify(obj, (k, v) => {
        if (v instanceof Node) return 'Node';
        if (v instanceof Window) return 'Window';
        return v;
      }, ' ');
    }
    

提交回复
热议问题