How to use the JSON.stringify method in web worker and the extension methods such as Object.keys of ES2015

worker is independent of window objects and does not have access to dom and related methods, but beyond that, it has recently been found that many common methods cannot be used in web worker. Such as JSON.stringify, Object.keys, Object.assign, Object.values, etc.

you can determine that these methods are available within the worker by typing the output from console.log.

but the actual execution will output the following error.

ReferenceError: _stringify2 is not defined
    at blob:http://localhost:8080/321543fe-b62e-41bf-abf7-2e2da6770ada:4
blob:http://localhost:8080/321543fe-b62e-41bf-abf7-2e2da6770ada:11

ReferenceError: _keys2 is not defined
    at blob:http://localhost:8080/321543fe-b62e-41bf-abf7-2e2da6770ada:9
blob:http://localhost:8080/321543fe-b62e-41bf-abf7-2e2da6770ada:16

ReferenceError: _values2 is not defined
    at blob:http://localhost:8080/321543fe-b62e-41bf-abf7-2e2da6770ada:14

my browser is the latest version of Chrome

related codes

execute in worker:

  console.info("way-finding worker init.")
  try {
    console.info(JSON.stringify)
  } catch (e) {
    console.info(e)
  }
  try {
    console.info(Object.keys)
  } catch (e) {
    console.info(e)
  }
  try {
    console.info(Object.values)
  } catch (e) {
    console.info(e)
  }

I don"t know if there is a problem with the use of worker. I hope some friends can give me some advice. thank you.

May.09,2022

totally.
clipboard.png

look at some of the keys in your error report have been converted. Maybe the code you compiled using some build tool (such as babel) is not as good as you expected
check your compiled code


can I ask how to solve this? In the next rookie, just started to learn

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b409db-2c51e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b409db-2c51e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?