Using VBScript function in JScript when Language=VBScript

你离开我真会死。 提交于 2019-12-24 06:51:49

问题


I know it is possible to use functions coded in VBScript if language="JScript" as follows :

<%@ language="JScript" %>
<% Response.Write(myFunc()); %>
<script runat="server" language="vbscript">
    Function myFunc
        myFunc="test"
    End Function
</script>

However, before refactoring a script in JScript, I wanted to know if, assuming the language is set to be VBScript, is there still a possibility to use VBScript functions in the JScript. Or, in that case, only the other way aroud is possible.

Thanks!


回答1:


I have tested this before using jscript, vbscript and Python. It is possible to call a function from one language in a block of code from another and work with the results.

There are some caveats though:

You need to make sure the function returns a type that the other language can recognize; so returning Python objects to vbscript will not work, but if you use simple types like strings, numbers and booleans it is possible. I think even arrays work between vbscript and jscript.

The second thing to consider is that there is a sequence in the order in which the scripts are processed on the server; I don't know exactly anymore what it is, but ASP will first process one language, and after that the other.
This can lead to strange things happening when your code calls a function in a different language and that function can't be found because ASP needs to still process the language for that function.

As long as you keep your execution in functions and make sure you only write code outside of these functions in one specific language, this shouldn't be a problem.

Here's more info on the order of execution: http://www.kidslovepc.com/asp/order_execution.shtml



来源:https://stackoverflow.com/questions/12174692/using-vbscript-function-in-jscript-when-language-vbscript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!