最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

扩展Map.set还保存新条目在磁盘上

运维笔记admin20浏览0评论

扩展Map.set还保存新条目在磁盘上

扩展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'));
发布评论

评论列表(0)

  1. 暂无评论