Back to functions

nerdamer.register


register

Registers a module function with nerdamer. The object needs to contain at a minimum, a name property (text), a numargs property (int), this is -1 for variable arguments or an array containing the min and max arguments, the visible property (bool) which allows use of this function through nerdamer, defaults to true, and a build property containing a function which returns the function to be used. This function is also handy for creating aliases to functions. See below how the alias D was created for the diff function).

Usage: nerdamer.register(o)


Parameters

Object | Object[] o An array of objects to be registered

Returns

nerdamer

EXAMPLES:
var core = nerdamer.getCore();
var _ = core.PARSER;
function f(a, b) {
//use clone for safety since a or b might be returned
var sum = _.add(a.clone(), b.clone());
var product = _.multiply(a.clone(), b.clone());
return _.multiply(sum, product);
}
//register the function with nerdamer
nerdamer.register({
   name: 'myFunction',
   numargs: 2,
   visible: true,
   build: function(){ return f; }
});

//create an alias for the diff function
var core = nerdamer.getCore();
nerdamer.register({
    name: 'D',
    visible: true,
    numargs: [1, 3],
    build: function(){ return core.Calculus.diff; }
});

var x = nerdamer('D(cos(x),x)');
console.log(x.toString());
OUTPUT:
Back to functions