VBScript and JavaScript mutual call method

zhaozj2021-02-16  35

VBScript and JavaScript mutual call method

The ASP has the ability to manage different language scripts, which can automatically call the appropriate scripting engine to explain script code and perform built-in functions. The ASP development environment provides two scripting engines, namely VBScript, and JScript. However, developers are not limited to only two languages, as long as they can provide the appropriate ActiveX scripting engine to use any scripting languages.

The selection of scripting languages ​​is often based on many different reasons: it may be the most familiar language of developers, possibly to provide maximum feature support for a given project, or may be the most efficient. Different environments and requirements make us pay attention to different factors when choosing scripting languages, and also makes us not directly provide other language inherent functions, or a script is already written. It is another scripting language.

What should I do at this time? Do you need to rewrite these scripts with the scripting language used? Or is it possible to call other scripting's built-in functions in a scripting language? This article wants to make the VBScript script and JScript script interact in the ASP application to maximize the feature support for both scripting languages.

First, the built-in function of VBScript and JScript

In VBScript and JScript, a large number of built-in function functions are the same or similar. However, functions built in a scripting language are not always corresponding in another scripting language. For example, VBScript provides a number of functions for operating strings and formatted data, which do not exist in JScript. These functions include strreverse (), filter (), and formatcurrency (). On the other hand, functions provided by JScript for managing arrays, string coding, etc. are not defined in VBScript, such as Join (), Reverse (), POW (), bit operation, escape (), and unescape () Wait.

So, what should I do if I need a VBScript function in a JScript program?

Second, the mutual call of the heterogeneous script

If you need to call a function in a VBScript in the JScript script, you should write a VBScript user-defined function (call the VBScript built-in function here) and then call the Used JScript function in the JScript script call this user-defined function.

For example, if the VBScript built-in function to be called is formatcurrency (), you can declare the following custom functions: