calculator.functions

calculator.functions.complex

calculator.functions.vector

etc.

that contain the actual JS functions for commands. These objects are called "function collections" but are really ordinary JS objects that happen to contain Functions as properties.

An alias ME is available that is simply a shortcut to calculator.functions.

So, a function like sin would be found in calculator.functions.sin (or ME.sin) and calculator.functions.complex.sin (ME.complex.sin), etc.

In JS, the dot-notation is just syntactic sugar equivalent to the following: calculator.functions["sin"] (ME["sin"]), and calculator.functions.complex["sin"] (ME.complex["sin"]).

As a convenience when you write JS programs, you can actually write just

- Code: Select all
`sin(x)`

To call the complex version, though, you have to either write

- Code: Select all
`complex.sin(x)`

or

- Code: Select all
`ME.complex.sin(x)`

The same goes for functions defined in your folder (be they JavaScript or RPL). If you have a function called foo in your folder, you can invoke it from JavaScript like so:

- Code: Select all
`foo(x)`

Now, if you need a handle to the actual function and look it up by name (to dynamically get access to a JS function), here's how you can do that:

Let's assume the name of the function you want to call is in a variable name.

For a stock function with real data type: calculator.functions[name] or ME[name]

For a function in the current folder: calculator.functions[calculator.currentDataCategory] or ME[calculator.currentDataCategory]

For a function in another folder: calculator.functions[foldername] or ME[foldername] (where foldername is something like "Tools")

Once you have the function, you can invoke it with JavaScript's call or apply functions.

Examples:

Call a real-valued function by name:

- Code: Select all
`function(name, val) {`

var f = ME[name];

return f.call(ME, val);

}

or

- Code: Select all
`function(name, val) {`

var f = ME[name];

var args = [];

args.push(val);

return f.apply(ME, args);

}

Call a function (JavaScript *or* RPL) by name, defined in the current folder:

- Code: Select all
`function(name, val) {`

var f = ME[calculator.currentDataCategory][name];

return f.call(ME[calculator.currentDataCategory], val);

}

or

- Code: Select all
`function(name, val) {`

var f = ME[calculator.currentDataCategory][name];

var args = [];

args.push(val);

return f.apply(ME[calculator.currentDataCategory], args);

}