Created
December 24, 2020 20:40
-
-
Save oliverjumpertz/6db42f594201d4d945428879fb362afc to your computer and use it in GitHub Desktop.
Creating a vanilla dictionary
This file contains hidden or 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
const dict = {}; | |
dict.__proto__; // => {} | |
console.log(dict.hasOwnProperty); // => f hasOwnProperty() {} | |
const emptyDict = Object.create(null); | |
emptyDict.__proto__; // => undefined | |
emptyDict.hasOwnProperty; // => undefined | |
// ❗️ Anyone can modify the object prototype from the outside | |
Object.prototype.myFunction = function () {}; | |
// ❌ As you can see here, dict was affected. | |
dict.myFunction; // => f () {} | |
// ✅ But our emptyDict remains unaffected! | |
emptyDict.myFunction; // => undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment