1.0.1 • Published 5 years ago

xrtlibrary-outputparameter v1.0.1

Weekly downloads
-
License
BSD-3-Clause
Repository
-
Last release
5 years ago

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.