
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
array-reduce-prototypejs-fix
Advanced tools
Safe `Array.reduce()` when using PrototypeJS v1.6 and lower.
PrototypeJS was a popular JS library many years ago. It extended and changed native objects. Which led to collisions with newer versions of browsers, if they implemented methods with the same names. This is the case of Array.reduce()
(see native versus Prototype's implementation).
This, kids, is exactly why you should never touch native objects. And this is why PrototypeJS lost JavaScript libraries war and Jquery won.
Anyway, if you need to use Array.reduce()
in a project that uses PrototypeJS v1.6 and lower (they removed it from v1.7), this module should help you. Since PrototypeJS replaced the original method, there's no way to get it back. We could replace the method with polyfill, but that would potentially break the code expecting PrototypeJS' method. So instead we create a new function. It checks for the presence of PrototypeJS. If it is there, it uses polyfill. Otherwise it uses native implementation.
Just remember that this should be a temporary fix. Real fix would be to get rid of PrototypeJS from your project. Or at least to upgrade it to v1.7.
Does exactly the same as native Array.reduce()
, but is safe to use when PrototypeJS v1.6 or lower is present.
Parameters
array
[Array](default []) Array object upon which you would call the native reduce()
method.params
...Any Rest of parameters which you would provide to native reduce()
method.Returns Any
If you found any bugs, if you have feature requests or any questions, please, either file an issue at GitHub or send me an e-mail at riki@fczbkk.com.
Safe Array.reduce when usingPrototypeJS v1.6 and lower is published under the MIT license.
FAQs
Safe `Array.reduce()` when using PrototypeJS v1.6 and lower.
The npm package array-reduce-prototypejs-fix receives a total of 801 weekly downloads. As such, array-reduce-prototypejs-fix popularity was classified as not popular.
We found that array-reduce-prototypejs-fix demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.