Fellow Mozillian Daniel Buchner, curator of the X-Tag project and clever developer who showed us how to detect dom node insertions using CSS animations, recently showed me a new JavaScript feature I'd never heard of: the SCRIPT element's afterscriptexecute event. This event, when detected within the document, provides developers insight as to when specific SCRIPT elements are executed.
研究员Mozillian 丹尼尔·毕希纳的馆长X-标签项目和聪明的开发商谁向我们展示了如何检测使用CSS动画的DOM节点插入 ,最近发现我一个新JavaScript功能,我从来没有听说过的:在SCRIPT元素的afterscriptexecute事件。 在文档中检测到此事件后,开发人员可以洞悉何时执行特定的SCRIPT元素。
View Demo 观看演示The following snippet listens for script executions on the page and logs the specific SCRIPT element to the console after executed:
以下代码段侦听页面上的脚本执行,并在执行后将特定的SCRIPT元素记录到控制台:
<script id="my_script" type="text/javascript"> document.addEventListener('afterscriptexecute', function(e){ console.log('Script executed: ', e.target); }, false); </script> <script type="text/javascript">console.log('foo')</script> <script type="text/javascript">console.log('bar')</script>This technique will be incredibly useful for debugging complex JavaScript applications, allowing developers to know exactly which script had just been injected and executed.
该技术对于调试复杂JavaScript应用程序非常有用,它使开发人员可以准确地知道刚刚注入并执行了哪个脚本。
View Demo 观看演示Daniel has a knack for finding useful new techniques and this tip will be helpful down the road. Unfortunately only Firefox has implemented this event but I look forward to WebKit support soonish. Can you think of how you'd use this event?
丹尼尔(Daniel)有找到有用的新技术的诀窍,这个技巧对以后的工作很有帮助。 不幸的是,只有Firefox实施了此活动,但我希望WebKit尽快得到支持。 您能想到如何使用此事件吗?
翻译自: https://davidwalsh.name/afterscriptexecute
相关资源:jdk-8u281-windows-x64.exe