4 ms·
He/she should have just used a regular method. Yeah it makes the code pretty, but it pollutes every library in your environment. You don't do this for the exact
by secoif 13y ago
He/she should have just used a regular method. Yeah it makes the code pretty, but it pollutes every library in your environment. You don't do this for the exact same reason you don't use globals. String.prototype is a global. Don't mess with it.
By not messing with globals, node allows you to safely load multiple versions of the same module and not worry about strange runtime environment changes. It probably doesn't matter in this trivial case, but node's primary win is how easy and safe it is to write and share modular code so yeah, prototype pollution is a destructive anti-pattern.