UNPKG

mathjs

Version:

Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser and offers an integrated solution to work with numbers, big numbers, complex numbers, units, and matrices.

39 lines (33 loc) 969 B
var OperatorNode = require('./OperatorNode'); /** * @constructor TernaryNode * @extends {OperatorNode} * * A conditional expression * * condition ? truePart : falsePart * * @param {String[]} ops The operator symbols, for example ['?', ':'] * @param {String} fn The function name, for example 'ifElse' * @param {Node[]} params The operator parameters, should contain three parameters. */ function TernaryNode (ops, fn, params) { if (!(this instanceof TernaryNode)) { throw new SyntaxError('Constructor must be called with the new operator'); } // TODO: validate input this.ops = ops; this.fn = fn; this.params = params; } TernaryNode.prototype = new OperatorNode(); /** * Get string representation * @return {String} str */ TernaryNode.prototype.toString = function() { return this.params[0] + ' ' + this.ops[0] + ' ' + this.params[1] + ' ' + this.ops[1] + ' ' + this.params[2]; }; module.exports = TernaryNode;