网络工作者console.log
是我一个人的问题,还是 console.log()
对 HTML5 Web 工作人员的要求太高了?
我知道操作 DOM 会被阻止,因为它存在潜在危险,但是 console.log()
真的有可能被多线程工作人员恶意利用吗?
Is it just me, or is console.log()
too much to ask for from HTML5 web workers?
I know that manipulating the DOM is blocked because it is potentially dangerous, but is there really any possibility that console.log()
could be maliciously exploited by a multithreaded worker?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
同意事情会好得多,但使用
postMessage
破解原始console.log
并不太难。 David Flanagan 在这里有一个很好的包装器。Agreed things would be a lot nicer, but it's not too hard to hack up a primitive
console.log
usingpostMessage
. David Flanagan has a nice wrapper here.只是想发布
console.log
现在至少可以在 Chrome 浏览器中实现。我不知道它是添加到哪个版本,但 35.0.1916.153 m 有它。
限制
不过它有一个小限制,它只能输出基元(字符串、数字、布尔值),有时是单维数组。
它只能采用控制台日志中的第一个参数。
正常控制台日志:
工作控制台日志:
您可以使用console.log(JSON.stringify({ status: _status })); 但这不会处理循环引用对象,并且不会以漂亮的/形式输出易于读取的对象。
更新:您可以通过执行
console.log(JSON.stringify(someObject, null, " "));
使用 stringify 获得漂亮的打印结果。Just wanted to post that
console.log
is now possible at least 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:
Worker Console log:
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, " "));
.