picomath/picomathInstance.js

25 lines
655 B
JavaScript

/* Core of picomath: generates an instance */
import poortf from './poortf.js'
export default function picomathInstance (instName) {
/* Since we have to do it all the time, when we call a picomath instance
* as a function, it takes a name and 0 or more implementations add adds
* them to its poortf property named name, returning that property value.
*/
function fn (name, imps) {
if (name in fn) {
fn[name].addImps(imps)
} else {
fn[name] = poortf(name, imps)
}
return fn[name]
}
Object.defineProperty(fn, 'name', {value: instName})
return fn
}