Sometimes I am very tempted to just add this to a project, but of course you never know what it would do to third-party dependencies:
Object
.getOwnPropertyNames(Object.prototype)
.forEach((p) => delete Object.prototype[p]);
Even though I know I will probably never run into this scenario, it drives me crazy that we all use JavaScript plain objects as lookup dictionaries and make assumptions about property lookups:
type BlogPostsDictionary = Record<string, BlogPost>;
let postsBySlug: BlogPostsDictionary;
let slug: string;
let post: BlogPost = postsBySlug[slug];
Knowing in the back of my mind that if slug
were "constructor"
, "hasOwnProperty"
, etc., then post
would be, of all things, a function!
(Yes, of course there's always Object.create(null)
, but you'd never get to use shorthand {}
— you would even need to wrap any instances of the { ... }
spread operator syntax!)