最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

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

IT培训 admin 9浏览 0评论

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

评论列表 (0)

  1. 暂无评论