使您JavaScript成为Windows .exe

These days an average web developer needs to have a broad matrix of skills in order to do his/her job. HTML, CSS, JavaScript, AJAX, XML, some server side language, some linux skills, some apache, some database skills, standards, accessibility, SEO, the list goes on. Parts of the list are also multiplied by (or raised to the power of?) the number of browsers you want to support. Crazy, isn't it? We're such optimists trying to make stuff work in such an environment.

如今,一般的Web开发人员需要具备广泛的技能才能完成工作。 HTML,CSS,JavaScript,AJAX,XML,一些服务器端语言,一些linux技能,一些apache,一些数据库技能,标准,可访问性,SEO,等等。 列表的一部分还乘以(或提高到?的幂)要支持的浏览器数量。 疯了,不是吗? 我们是这样的乐观主义者,他们试图在这种环境下工作。

There's gotta be an easier way to write code that does something meaningful! Yes, there is, it's called JavaScript. You learn JavaScript, you learn it well, and you don't need to learn anything else. Isn't that cool? JavaScript is, practically, everywhere. Learn JavaScript and you can:

必须有一种更简单的方法来编写可实现有意义的代码! 是的,这就是所谓JavaScript。 您学习JavaScript,学习得很好,并且不需要学习其他任何东西。 那不是很酷吗? 实际上,JavaScript无处不在。 学习JavaScript,您可以:

  • create rich and powerful web applications (the kind that runs inside the browser)

    创建丰富功能强大的Web应用程序(在那种在浏览器内运行)

  • write server-side code such as ASP scripts or for example code that is run using Rhino (A JavaScript engine written in Java)

    编写服务器端代码(例如ASP脚本)或使用Rhino(用Java编写JavaScript引擎)运行的代码
  • create rich media applications (Flash, Flex) using ActionScript which is based on ECMAScript, which is JavaScript

    使用基于ECMAScript(JavaScript)的ActionScript创建富媒体应用程序(Flash,Flex)
  • write scripts that automate administrative tasks on your Windows desktop, using Windows Scripting Host

    使用Windows脚本宿主编写在Windows桌面上自动执行管理任务的脚本
  • write extensions/plugins for a plethora of desktop application such as Firefox or Dreamweaver

    为大量的桌面应用程序(例如Firefox或Dreamweaver)编写扩展程序/插件
  • create web applications that store information off-line on user's desktop, using Google Gears

    使用Google Gears创建可将信息离线存储在用户桌面上的Web应用程序

  • create Yahoo!, or Mac, or dunno-what-type-of widgets

    创建Yahoo!,Mac或dunno-what-type-of小部件
  • create Windows apps (those that end in .exe) and libraries (.dll)

    创建Windows应用程序(以.exe结尾的应用程序)和库(.dll)

I'm sure the list above is not even complete.

我确定上面的清单还不完整。

OK, it's a joke that with one programming skill only you'll be employed for life, but it's a fun thought anyway. Off to the main topic of the post.

好吧,开个玩笑说,只有一种编程技能才能让您终身受雇,但这还是很有趣的想法。 转到帖子的主要主题。

脚本 (JScript)

This is Microsoft's version of JavaScript (yep, the thing that annoys us *sometimes* in IE) and can also be used to create server side pages (ASP, ASP.NET) or desktop applications. Apparently JScript is now called JScript.NET and can be compiled to create .exe files. Let's see how.

这是MicrosoftJavaScript版本(是的,在IE中有时会惹恼我们),也可用于创建服务器端页面(ASP,ASP.NET)或桌面应用程序。 显然,JScript现在称为JScript.NET,可以进行编译以创建.exe文件。 让我们看看如何。

编译器 (The compiler)

The compiler (program that creates programs) is an exe file called jsc.exe (JScriptCompiler) and is part of the .NET framework. Good news is that you can use it without installing any MS IDE (whatever Visual Studio is called these days), free of charge. Even better, maybe it's already there, on your machine. I searched my completely normal Windows XP machine that doesn't have any special MS tools and was able to find two copies of the compiler! You can search for "jsc.exe" and in case you don't already have it, you can read how to get it here.

编译器(创建程序的程序)是一个名为jsc.exe的exe文件( JS cript C ompiler),并且是.NET Framework的一部分。 好消息是,您可以免费安装它而无需安装任何MS IDE(如今称为Visual Studio)。 甚至更好,也许它已经在您的机器上了。 我搜索了没有任何特殊MS工具的完全普通的Windows XP计算机,并且能够找到该编译器的两个副本! 您可以搜索“ jsc.exe”,如果您还没有的话,可以在此处阅读如何获取它。

So once you find your jsc.exe (found one o' mine in C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727), then add this path to your environment path: Right-click My Computer - Advanced - Environment Variables - System Variables - Path - Edit

因此,一旦找到jsc.exe(在C:\ WINDOWS \ Microsoft.NET \ Framework \ v2.0.50727中找到一个),然后将此路径添加到您的环境路径中:右键单击我的电脑-高级-环境变量-系统变量-路径-编辑

Now open command prompt (Start - Run - "cmd" - OK) and type "jsc"+ENTER. You should see a list of help options for the compiler. Cool!

现在打开命令提示符(开始-运行-“ cmd”-确定),然后键入“ jsc” + ENTER。 您应该看到编译器的帮助选项列表。 凉!

第一个.exe(以年为单位) (First .exe (in years))

The last time I created an .exe file is probably yeeears ago, when I was this Visual Basic king, writing a desktop application that takes a directory of images and creates a web gallery (example)

我上次创建.exe文件的时间可能是在几年前,那时我是Visual Basic的王者,他编写了一个桌面应用程序,该应用程序使用一个图像目录并创建一个网络画廊(示例)

OK, lets create a simple application.

好的,让我们创建一个简单的应用程序。

cd ..
mkdir myapps
cd myapps

Create a file called hello.js with the following content:

创建一个具有以下内容的名为hello.js的文件:

var d = new Date();
var n = Math.random();
print('Hello, \\ntoday is ' + d + '\\nand this is random - ' + n);

Now let's compile!

现在开始编译!

C:\\myapps>jsc hello.js
Microsoft (R) JScript Compiler version 8.00.50727
for Microsoft (R) .NET Framework version 2.0.50727
Copyright (C) Microsoft Corporation 1996-2005. All rights reserved.

No error messages, so we'll take that as an OK 😉 Let's check:

没有错误消息,因此我们将其作为OK😉让我们检查一下:

C:\\myapps>dir
 Volume in drive C has no label.
 Volume Serial Number is B96A-95DB

 Directory of C:\\myapps

08/31/2007  07:33 PM    <DIR>          .
08/31/2007  07:33 PM    <DIR>          ..
08/31/2007  07:34 PM             4,096 hello.exe
08/31/2007  07:33 PM               109 hello.js
               2 File(s)          4,205 bytes
               2 Dir(s)  40,287,092,736 bytes free

YES! An .exe was created! Without further ado, let's run it already!

是! 已创建一个.exe! 事不宜迟,让我们开始运行吧!

C:\\myapps>hello
Hello,
today is Fri Aug 31 19:34:32 PDT 2007
and this is random - 0.5855108083158316

That's so cool, the compiled program works!

太酷了,编译后的程序可以工作了!

制作DLL (Making a DLL)

Now, we're convinced that we have a good thing going here, so let's create a DLL, meaning create a library that other applications can use.

现在,我们确信这里有一件好事,所以让我们创建一个DLL,即创建一个其他应用程序可以使用的库。

JScript.NET has the notion of namespaces and packages (which we usually fake on the web) and class-based objects (eww! well, it supports the prototype stuff as well). So if we simply wrap our code in a package and a class and we create a new file LibHello.js:

JScript.NET具有名称空间和程序包(我们通常在网络上伪造)和基于类的对象(ew !,它也支持原型的东西)的概念。 因此,如果我们仅将代码包装在一个包和一个类中,然后创建一个新文件LibHello.js:

package LibHello {
    class Hello {
        function say() {
            var d = new Date();
            var n = Math.random();
            return 'Hello, \\ntoday is ' + d + '\\nand this is random - ' + n;
        }
    }
}

Let's compile this into a library, we need the /t:library option when compiling

让我们将其编译为一个库,编译时需要/ t:library选项

C:\\myapps>jsc /t:library LibHello.js

This creates hello.dll and we have a library!

这将创建hello.dll,我们有一个库!

消耗lib (Consuming the lib)

Finally, let's create an app that leverages the new library we just created.

最后,让我们创建一个利用我们刚刚创建的新库的应用程序。

Create consumer.js with the following:

使用以下命令创建consumer.js:

import LibHello;
var h = new LibHello.Hello();
print(h.say());

Compile and run:

编译并运行:

C:\\myapps>jsc consumer.js

C:\\myapps>consumer.exe
Hello,
today is Fri Aug 31 19:53:29 PDT 2007
and this is random - 0.45013379838789525

Nice and easy.

好,易于。

所以呢? (So what?)

I didn't have time to experiment, but I'm pretty sure you can take tools such as jsmin or jslint and easily compile them into libraries that can be consumed from windows apps, or VBA scripts in Access, Powerpoint, etc. Imagine you're writing some documentation in Word, you select some JS code you just wrote and JSlint it. That would be nice.

我没有时间进行实验,但是我很确定您可以使用jsminjslint之类的工具并将其轻松编译为可从Windows应用程序或Access,Powerpoint等中的VBA脚本使用的库。在Word中编写一些文档,选择一些刚编写的JS代码并对其进行JSlint处理。 那样就好了。

BTW, remember how we used /t:library option to produce a .dll and not an .exe? Well, there's also the option /t:winexe which creates a windows application I mean with the window and everything and not a console app. OK, let's give it a shot, create win.js with the following:

顺便说一句,还记得我们如何使用/ t:library选项生成.dll而不是.exe吗? 好吧,还有/ t:winexe选项,它创建一个我指的是带有窗口和所有内容的Windows应用程序,而不是控制台应用程序。 好,让我们试一下,使用以下命令创建win.js:

import System.Windows.Forms; // this has a MessageBox class
import LibHello;

var h = new LibHello.Hello();
MessageBox.Show(
        h.say(),
        "Dude!",
        MessageBoxButtons.OK,
        MessageBoxIcon.Exclamation
);

Compile:

编译:

C:\\myapps>jsc /t:winexe win.js

Double click in windows explorer and you have a nice little unquestionably useful Windows application 😉

双击Windows资源管理器,您将获得一个毫无疑问的好用的Windows应用程序😉

Tell your friends about this post on Facebook and Twitter

FacebookTwitter上告诉您的朋友有关此帖子的信息

翻译自: https://www.phpied.com/make-your-javascript-a-windows-exe/

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
appium-windows-1.17.1-1.exe是Appium的一个版本。Appium是一个开源的自动化测试框架,用于移动应用程序的自动化测试。它支持多种操作系统,包括Windows。版本号1.17.1-1表示这是Appium的第1.17.1-1个发布版本。 这个.exe文件是用于在Windows操作系统上安装和运行Appium的可执行文件。它包含了Appium所需的所有文件和组件,可以一键安装和启动Appium。当你需要在Windows上进行移动应用程序的自动化测试时,你可以下载这个.exe文件并运行它,然后按照安装向导的提示进行操作。安装完成后,你就可以使用Appium的命令行界面或者编程语言的客户端库来编写和运行自动化测试脚本。 通过Appium,你可以模拟用户在移动设备上的各种操作,比如点击、滑动、输入等,来测试你的移动应用程序的功能和稳定性。你可以使用多种编程语言来编写测试脚本,比如JavaPythonJavaScript等。通过Appium的跨平台支持,你可以在Windows、Mac、Linux等操作系统上执行自动化测试,而不需要为不同的操作系统编写不同的测试脚本。 总之,appium-windows-1.17.1-1.exe是一个用于在Windows上安装和运行Appium的可执行文件,它是一个开源的自动化测试框架,用于移动应用程序的自动化测试。它提供了丰富的功能和灵活的编程接口,帮助开发人员更高效地进行移动应用程序的自动化测试。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值