Glen Whitney
e5ec1083e3
Plus a test example where an instance is initialized to have only addition, and then that instance is extended to complex numbers, at which point it has number and complex addition but not negation or subtraction (at all).
24 lines
636 B
JavaScript
24 lines
636 B
JavaScript
import { isTF } from '../poortf.js'
|
|
import createComplex from './complex.js'
|
|
|
|
/* Add all the complex methods for the number methods that are
|
|
* already in the instance: */
|
|
export default async function extend(pmath) {
|
|
for (const item in pmath) {
|
|
if (isTF(pmath[item])) {
|
|
// might be a number method, try importing
|
|
const modulePath = `./${item}.js`
|
|
try {
|
|
const { default: create } = await import(modulePath)
|
|
create(pmath)
|
|
} catch (err) {
|
|
// Guess it wasn't a number method; no worries
|
|
}
|
|
}
|
|
}
|
|
createComplex(pmath)
|
|
}
|
|
|
|
|
|
|