2

每当我尝试在 SciTE(Scintilla 文本编辑器)中运行“.js”文件时,我几乎总是会收到一条错误消息,指出某些变量未定义。我猜 SciTE 没有很多 JavaScript 库,但我不确定。

几次搜索后,我找到了 两篇关于如何让 SciTE 将 JavaScript 测试打印到其输出的博客文章,而不是在按 F5 测试代码时打开 Web 浏览器。

我都试过了,但是我在第一个帖子的解决方案中遇到了与以前相同的错误,或者我收到了一个错误,说“'jrunscript' 不被识别为内部或外部命令,可运行程序或批处理文件”与第二个方法。

那么,是否可以在 SciTE 中测试 JavaScript 代码并将 JavaScript 输出(或错误)打印到 SciTE 的输出中?

我试过的简单示例代码:

控制台.log(“测试”)

我收到的错误消息:'Microsoft JScript 运行时错误:'控制台'未定义'

4

1 回答 1

3

What is SciTe?

SciTE is a SCIntilla based Text Editor. Lua is embedded with SciTe which allows you to access the Scintilla API.

# lua code example
`command.go.*.js=jrunscript $(FileNameExt)`

How to run js code in SciTe?

Create a file called testConsole.js with the following content.

var console = console || {};
console.log = ( console.log || function( str ){
    if( typeof print == "function" ){
        print( "LOG: " + str + "\n" );
    }
    return "LOG: " + str;
});
console.log( "Javascript works." );

Open testConsole.js in SciTe.

To run the code, press F5 or click Tools > Go.

An output window should appear showing

LOG: Javascript works.

How do I configure SciTe to run javascript?

I'm using SciTe 3.2.0. Located here In wscite\wsite320\cpp.properties at line: 424
change:
command.go.*.js=cscript /nologo $(FileNameExt)

to:
command.go.*.js=jrunscript $(FileNameExt)

if you want to use node.js, then change it to
command.go.*.js=node $(FileNameExt)

Make sure that you have the jrunscript or node in your path for the environment variables.
Tutorial here

Do I have jrunscript?

Here's the easiest way to check.
Open up run > type in cmd > type jrunscript.
js> should appear on the screen.

jrunscript.exe should be located here.
C:\Program Files\Java\jdk1.7.0_01\bin\jrunscript.exe

Download the lastest Java SDK if you can't find it.

Error Messages

What does 'Microsoft JScript runtime error: 'console' is undefined'

This means Microsoft JScript ran your javascript and couldn't find the variable console.
Define console to get rid of the error message.

var console = console || {};
console.log = ( console.log || function( str ){
    if( typeof print == "function" ){
        print( "LOG: " + str + "\n" );
    }
    return "LOG: " + str;
});

Microsoft JScript might be located here:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\jsc.exe

Error: Input Error: There is no file extension in "location"

Solution: You need to configure the cpp.properties file for javascript.

Error: script file test is not found

Solution: Rename the file. Make sure that it doesn't have any spaces.

于 2012-06-15T21:18:55.933 回答