web worker console.log

最后都变了- 提交于 2019-11-28 09:35:37
ebidel

Agreed things would be a lot nicer, but it's not too hard to hack up a primitive console.log using postMessage. David Flanagan has a nice wrapper here.

Just wanted to post that console.log is now possible atleast within the Chrome Browser.

I do not know which version it was added but 35.0.1916.153 m has it.

Limitation

There is a small limitation with it though, It can only output primitives (strings, numbers, booleans) sometimes single dimension arrays.

And it can only take the first argument within the console log.

Normal Console log:

console.log("status:", _status); // status: working
console.log({ status: _status }); // { "status": working }

Worker Console log:

console.log("status:", _status); // status:
console.log({ status: _status }); // [object Object]

You could use console.log(JSON.stringify({ status: _status })); but this would not handle circular referencing objects and will not output in a pretty/easy to read objects.

Update: You can get pretty print with stringify by doing console.log(JSON.stringify(someObject, null, " "));.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!