我有这个包含公式的变量(levelFormula),然后通过另一个变量的输出更新
var points = 100,
levelFormula = (Math.sqrt(2 * points + 255) - 5) / 10;
换句话说,如果 points 得到更新,那么 levelFormula 也是如此。问题是,如何检测 levelFormula 的值何时发生变化?
答案 0 :(得分:1)
如评论中所述,
var previousLevelFormula; // should be separated with below scope
...
var points = 100; // I guess it's from function parameter, because it will be changed so you need detection changes of levelFormula
var levelFormula = (Math.sqrt(2 * points + 255) - 5) / 10;
if (previousLevelFormula && previousLevelFormula != levelFormula) {
// it's changed
}
previousLevelFormula = levelFormula; // update previous value