VincentGarreau / particles.js

A lightweight JavaScript library for creating particles
https://vincentgarreau.com/particles.js/
MIT License
28.66k stars 4.81k forks source link

Make code compatible with ES5 strict mode #520

Closed kuankuan2007 closed 10 months ago

kuankuan2007 commented 12 months ago

In version v2.0.0, an error with the word "Uncaught TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them" appears. I try to fix the problem in the https://github.com/kuankuan2007/particles.js/tree/kuankuan2007

emiliodominguez commented 10 months ago

Hi @kuankuan2007, ran into the same issue since arguments.callee within the deepExtend declaration is deprecated and the strict mode doesn't like that. That being said, this should fix it:

Object.deepExtend = function(destination, source) {
    function extendRecursive(dest, src) {
        for (var property in src) {
            if (src.hasOwnProperty(property)) {
                if (src[property] && src[property].constructor && src[property].constructor === Object) {
                    dest[property] = dest[property] || {};
                    extendRecursive(dest[property], src[property]);
                } else {
                    dest[property] = src[property];
                }
            }
        }
    }

    extendRecursive(destination, source);
    return destination;
`};
kuankuan2007 commented 10 months ago

Yes, this is a very good solution.