feat: Selective loader that extends all/only existing number methods to complex
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).
This commit is contained in:
parent
29653f25c4
commit
e5ec1083e3
3 changed files with 47 additions and 2 deletions
23
complex/extendByComplex.js
Normal file
23
complex/extendByComplex.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
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)
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue