Working with “Out” Parameters in JavaScript

后端 未结 3 1829
星月不相逢
星月不相逢 2020-12-11 03:08

I am working with an ActiveX control in Internet Explorer 8 that is to display a save file dialog which let\'s the user choose a file name and file type (jpg, gif, etc). Th

相关标签:
3条回答
  • 2020-12-11 03:20

    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.

    0 讨论(0)
  • 2020-12-11 03:26

    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.

    0 讨论(0)
  • 2020-12-11 03:37

    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.

    0 讨论(0)
提交回复
热议问题