扩展Map.set还保存新条目在磁盘上
这不是生产只是为开发宗旨,从我离开时,我重新启动本地服务器的地方开始。
我尽量不修改生产代码这一点。我想打电话map.set(...)
时保存到磁盘上的新条目。该代码波纹管得到一个想法是什么我想要的。
// developing code that will be commented out in production
Map.prototype.set=()=>{
// new functionality save to disk with something like fs.writeFileSync()
return new Map.set() // keep the original functionality
}
// production code
const map = new Map().set('a',1)
回答如下:
如果我没有记错的话:
'use strict';
const oldSet = Map.prototype.set;
Map.prototype.set = function (key, value) {
console.log(key, value); // or other IO actions
oldSet.call(this, key, value);
};
const map = new Map();
map.set('a', 1);
console.log(map.get('a'));
扩展Map.set还保存新条目在磁盘上
这不是生产只是为开发宗旨,从我离开时,我重新启动本地服务器的地方开始。
我尽量不修改生产代码这一点。我想打电话map.set(...)
时保存到磁盘上的新条目。该代码波纹管得到一个想法是什么我想要的。
// developing code that will be commented out in production
Map.prototype.set=()=>{
// new functionality save to disk with something like fs.writeFileSync()
return new Map.set() // keep the original functionality
}
// production code
const map = new Map().set('a',1)
回答如下:
如果我没有记错的话:
'use strict';
const oldSet = Map.prototype.set;
Map.prototype.set = function (key, value) {
console.log(key, value); // or other IO actions
oldSet.call(this, key, value);
};
const map = new Map();
map.set('a', 1);
console.log(map.get('a'));
11136