Hard
You're building a plugin system that needs to safely extend built-in objects. What's wrong with this implementation and which solution correctly fixes the issues?
1function installPlugin(pluginName, methods) {2 const targets = {3 array: Array.prototype,4 string: String.prototype,5 number: Number.prototype6 };78 // Current problematic implementation9 Object.keys(methods).forEach(methodName => {10 if (!targets[pluginName][methodName]) {11 targets[pluginName][methodName] = methods[methodName];12 }13 });14}1516// Usage example:17installPlugin('array', {18 last() {19 return this[this.length - 1];20 },21 random() {22 return this[Math.floor(Math.random() * this.length)];23 }24});