Last active
July 10, 2018 14:41
-
-
Save weinshel/c6676c36eead578eded3d2de5026eab5 to your computer and use it in GitHub Desktop.
math.js range override bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const math = require('mathjs') | |
// define factory functions for range and reshape | |
function myRangeFactory (type, config, load, typed) { | |
return (() => 12) | |
} | |
function myReshapeFactory (type, config, load, typed) { | |
return (() => 21) | |
} | |
const factoryArr = [ | |
{ | |
name: 'range', | |
factory: myRangeFactory | |
}, | |
{ | |
name: 'reshape', | |
factory: myReshapeFactory | |
}, | |
] | |
// uncomment to override using non factory function | |
// this will work, and subsequently overriding `range` using factory function will work | |
//math.import({ range: () => 13 }, { override: true }) | |
// attempt to override using factory function | |
// this works for reshape but NOT for range | |
math.import(factoryArr, { override: true }) | |
const rangeEval = math.eval('range(2,5)') | |
const reshapeEval = math.eval('reshape(2,5)') | |
// this _should_ be 12 | |
// if it is [2,3,4,5] then the original function was not overwritten | |
console.log('range(2,5) evaluates to', rangeEval) | |
// note that reshape can be overritten with a single factory function without issue | |
// should return 21 | |
console.log('reshape(2,5) evaluates to', reshapeEval) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"dependencies": { | |
"mathjs": "^5.0.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment