简体   繁体   English

如何通过脚本在Firefox / Chrome中运行JavaScript代码段

[英]How to run javascript snippets in firefox/chrome from a script

I am currently trying to learn javascript. 我目前正在尝试学习JavaScript。 Coming from a python/R background I find it really useful for learning purposes to be able to write code in a script in Rstudio/pyCharm which I can then execute in a interpreter by highlighting specific lines of code and then pressing a ctrl+enter or some other keyboard shortcut. 来自python / R背景,我发现能够在Rstudio / pyCharm中的脚本中编写代码对于学习非常有用,然后可以通过突出显示特定的代码行,然后按ctrl + enter或其他一些键盘快捷键。

The console available on firefox/chrome seems incredibly rich and useful for learning / testing specific pieces of code but I find it quite limiting that I can't store each line in a script with comments/notes to myself. firefox / chrome上可用的控制台似乎非常丰富,对于学习/测试特定代码段很有用,但是我发现它限制了我无法将每行都存储在带有注释/注释的脚本中。

Is there a way to run lines of javascript in firefox/chrome like pycharm & rstudio can with their respective interpreters or how is it usually recommend for people to learn the language in an efficient manner ? 有没有一种方法可以在Firefox / chrome中运行javascript行,例如pycharm和rstudio可以通过各自的解释器运行,或者通常建议人们以有效的方式学习该语言?

Use node.js which is a javascript runtime using v8 (powering the chrome console) You can get an REPL similar to Python. 使用node.js(这是使用v8的javascript运行时)(为chrome控制台供电),您可以获得类似于Python的REPL。

You cannot, however use it to modify the DOM or access the window. 但是,您不能使用它来修改DOM或访问窗口。 In such case, using an online IDE like jsfiddle or codepen might be a good alternative. 在这种情况下,使用jsfiddle或codepen之类的在线IDE可能是一个不错的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM