Skip to content

Instantly share code, notes, and snippets.

@Dmitriy-8-Kireev
Created January 15, 2019 21:57
Show Gist options
  • Save Dmitriy-8-Kireev/05cfcb6b19bae5607897922dacad28b3 to your computer and use it in GitHub Desktop.
Save Dmitriy-8-Kireev/05cfcb6b19bae5607897922dacad28b3 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/nidijac
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
/**
* Реализовать свой Map
* @constructor
*/
function XMap() {
return {
set: (key, value) => this[key]=value,
has: (key) => !!this[key],
get: (key) => this[key],
remove: (key) => delete this[key]
}
}
// Проверка
const map = new XMap();
const objKey = {foo: true};
map.set(123, 'ok');
map.set(objKey, 'fail');
map.has(objKey) && map.set(objKey, 'wow');
console.log(map.get(123)); // "ok"
console.log(map.get(objKey)); // "wow"
map.remove(123);
console.log(map.has(123)); // false
</script>
<script id="jsbin-source-javascript" type="text/javascript">/**
* Реализовать свой Map
* @constructor
*/
function XMap() {
return {
set: (key, value) => this[key]=value,
has: (key) => !!this[key],
get: (key) => this[key],
remove: (key) => delete this[key]
}
}
// Проверка
const map = new XMap();
const objKey = {foo: true};
map.set(123, 'ok');
map.set(objKey, 'fail');
map.has(objKey) && map.set(objKey, 'wow');
console.log(map.get(123)); // "ok"
console.log(map.get(objKey)); // "wow"
map.remove(123);
console.log(map.has(123)); // false</script></body>
</html>
/**
* Реализовать свой Map
* @constructor
*/
function XMap() {
return {
set: (key, value) => this[key]=value,
has: (key) => !!this[key],
get: (key) => this[key],
remove: (key) => delete this[key]
}
}
// Проверка
const map = new XMap();
const objKey = {foo: true};
map.set(123, 'ok');
map.set(objKey, 'fail');
map.has(objKey) && map.set(objKey, 'wow');
console.log(map.get(123)); // "ok"
console.log(map.get(objKey)); // "wow"
map.remove(123);
console.log(map.has(123)); // false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment