Working with “Out” Parameters in JavaScript

China☆狼群 提交于 2019-11-28 12:06:07

Edit: It seems that it's not possible to have "out" parameters in JavaScript/JScript.

Original: Perhaps the approach described in this article will work:

var saveFileName={}, saveFileType={}; // Empty "output" objects.
gxVideoPlayBack.SaveFileDialog("image", saveFileName, saveFileType);
alert(saveFileName.value); // The "value" attribute is assigned ...
alert(saveFileType.value); // ... by the "SaveFileDialog" method?

I suppose the idea is that the WSH wrapper for this native call will attempt to assign the "value" property of the given output parameters, so you can either override the value setter or just give it an object with a built-in value setter.

Wayne Burkett

All function arguments in JavaScript are passed by value (even if the value being passed is a reference to an object (which it is)). There is no pass-by-reference.

If SaveFileDialog modifies the objects referenced by saveFileName and saveFileType then you have access to those changes through your existing variables.

Martijn

Unfortunately, out/ByRef parameters will only work in JScript for objects; not for any other type (numbers, strings).

In this case, you’ll have to use VBScript, which does support ByRef arguments, or like maerics says, write a VB/VBScript wrapper for the SaveFileDialog method, which could return an object containing both file name and type.

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