Created
January 15, 2019 21:57
-
-
Save Dmitriy-8-Kireev/05cfcb6b19bae5607897922dacad28b3 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/nidijac
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Реализовать свой 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