如何在javascript中通过引用传递变量?从ActiveX函数读取数据,返回多个值 [英] How to pass variable by reference in javascript? Read data from ActiveX function which returns more than one value

查看:170
本文介绍了如何在javascript中通过引用传递变量?从ActiveX函数读取数据,返回多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ActiveX对象,我想在浏览器中使用(javascript)。

有一个我想调用的函数。它的原型是:

I have a ActiveX object which I want to use in the browser (javascript).
There is a function I want to call. Its prototype is:

function TOPOSFiscalPrinter.DirectIO(Command: Integer; var pData: Integer;
  var pString: WideString): Integer;

因此,该函数返回三个值:结果代码,pData和pString;

在javascript中,函数不更新变量pData和pString;

So, the function returns three values: result code, pData and pString;
In javascript the function does not update the variables pData and pString;

function test()
{
  var d=1, s="DIRECIO:";
  var code = opos.DirectIO(1024, d, s);

  alert(d); alert(s);
}

变量 d s 未更新。它们必须是d = 0且s =ED123456;

如何从函数中读取数据,该函数在javascript中返回多个值?

Variables d and s are not updated. They must be d=0 and s="ED123456";
How to read data from function which returns more than one value in javascript?

编辑

显然,Javascript总是按值传递参数,永远不会通过引用传递参数。

我可以做些什么来通过Javascript中的引用传递值,或者
我将不得不改变我的设计,只依赖于
值和返回值传递的参数。

EDIT
Apparently, Javascript always passes parameters by value, never by reference.
Is there anything I can do to pass values by reference in Javascript, or I will have to change my design to only rely on parameters passed by value and on return values.

推荐答案

为了提高效率,原始类型(主要是字符串/数字/布尔值)按值传递。诸如函数,对象,数组等的对象通过引用传递。您可以创建一个对象并传递它,例如{d:1,s:'directo'}然后更改值,因为您传递了一个引用。

Primitive types, primarily strings/numbers/booleans are passed by value for efficiency purposes. Objects such as functions, objects, arrays and the like are passed by reference. You can create an object and pass it, eg { d:1, s:'directo' } and then change the values because you're passing a reference.

这篇关于如何在javascript中通过引用传递变量?从ActiveX函数读取数据,返回多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆