xrtlibrary-outputparameter

1.0.1 • Public • Published

XRTLibrary-OutputParameter

Introduction

An output parameter (similar to "pass arguments by reference" in C++) container for JavaScript.

Installation

To install this package, you can use NPM by typing following command:

npm install xrtlibrary-outputparameter --save

Then you can import this library in your JavaScript code:

const XRTLibOutputParameter = require("xrtlibrary-outputparameter");

Or more simple...

const OutputParameter = require("xrtlibrary-outputparameter").OutputParameter;

Typical usages (examples)

Usage 1: General output parameter

function Test(output = new OutputParameter()) {
    output.setValue("world");
    return "Hello";
}
console.log(Test());                          //  => "Hello"
let world = new OutputParameter();
let hello = Test(world);
console.log(hello + " " + world.getValue());  //  => "Hello world"

Usage 2: Duplex parameter (in/out)

function Test(output = new OutputParameter()) {
    if (output.hasValue()) {
        console.log(output.getValue());
    }
    output.setValue("World!");
}
let parameter = new OutputParameter();
parameter.setValue("Hello");
Test(parameter);                    //  => "Hello"
console.log(parameter.getValue());  //  => "World!"

API

(Class) OutputParameter<T>

Output parameter container.

new OutputParameter()

Construct a new object.

parameter.setValue(newValue)

Set the value.

Parameter(s):

  • newValue (T): The new value.

parameter.hasValue()

Get whether the value has been set.

Return value:

  • (Boolean) True if so.

parameter.getValue()

Get the value.

Return value:

  • (?T) The value (NULL if not set).

parameter.clearValue()

Clear the value.

Readme

Keywords

none

Package Sidebar

Install

npm i xrtlibrary-outputparameter

Weekly Downloads

3

Version

1.0.1

License

BSD-3-Clause

Unpacked Size

5.2 kB

Total Files

6

Last publish

Collaborators

  • chinpui