考虑一下,我想将某些其他代码使用的某些配置属性临时设置为特定测试的某些遗憾值,然后恢复给定的原始值。有什么棘手的方法可以减轻这种痛苦:
var config = { a: 69 /*sane value here*/ }
let v = config.a //store the previous value
config.a = 66 //devil numbers I don't want in my life but for the sake of continuing my existence I'll do some evil
//test here with the above value
config.a = v //return to the previous value
我在考虑一些不可见的数组,我可以将pop推入(如堆栈?)。