通过引用传递给JavaScript中的COM对象

时间:2015-10-22 15:14:22

标签: javascript

尝试将i变量传递给必须更改值的test函数:

<HTML>
<HEAD>
<TITLE> Welcome to my site</TITLE></HEAD>
<BODY>
<SCRIPT LANGUAGE="JAVASCRIPT">

var atl = new ActiveXObject("ATL.Object.1");
var i =6;
atl.test(i);
document.write(i);

</SCRIPT>
</BODY>

但在输出中我还有6。如何通过引用传递值?

1 个答案:

答案 0 :(得分:0)

在Javascript上通过引用传递不存在。你可以使用一个对象来传递,它就像通过引用传递一样。

例如:

    var atl = new ActiveXObject("ATL.Object.1");
    var i = { value: 6};
//if ActiveXObject does not work with your Object, than you need to make an adapter or store the value back to i
    atl.test(i);
    document.write(i.value);