用vbscript写一个方法,间接调用要调用的方法。 参数和返回值以数组的形式传递。
简单来说,javascript中的数组不是真正的数组,它是Object。 传到vbscript中,不认为它是数组,不能用下标的形式引用。 所以,给Array追加了get和set方法。
同时,在vbscript中用vbs变量接收数组的值,用它执行vbs的function, 然后,再将vbs变量值set回数组。
由于数组在javascript中是引用传递,即byRef的, 所以javascript中能看到改变后的值。
<script language="vbscript"> sub xx(ax) ax=100 end sub
aa=1 call xx(aa) msgbox("vb call:" & aa)
function exeFunc(funcName,jsArray) msgbox "js array type:" & typename(jsArray) msgbox "array(0):" & jsArray.get(0) dim abc abc = jsArray.get(0) execute "call " & funcName & "(abc)" msgbox "vb return value:" & abc jsArray.set 0,abc end function
</script>
<script language="javascript">
var bb=2 xx(bb) alert("js call:" + bb)
Array.prototype.get = function(prop) { return this[prop]; }
Array.prototype.set = function(prop,value) { this[prop]=value; }
var yy=new Array() yy[0]=2 yy[1]=3
exeFunc("xx",yy) alert("js return value:" + yy[0]) </script> ============================ 以下是javascript和vbscript中Array的对比:
Earlier I alluded to the fact that JScript arrays are objects but VBScript arrays are not. What's up with that?
It's kind of strange. Consider the properties of a JScript array. A Jscript array is
* one dimensional.
* associative; JScript arrays are indexed by strings. Numeric indices are actually converted to strings internally.
* sparse: arr[1] = 123; arr[1000000] = 456; gives you a two-member array, not a million-member array.
* an object with properties and methods.
Whereas a VBScript array is
* multi-dimensional
* indexed by integer tuples
* dense
* not an object
It is hard to come up with two things that could be more different and yet both called "array".
|