Git Product home page Git Product logo

Comments (3)

bigtimebuddy avatar bigtimebuddy commented on June 3, 2024

I cannot reproduce: https://jsfiddle.net/bigtimebuddy/pjvrebs8/

Please provide more information or an example that minimally reproduces the problem.

from pixijs.

meghe2000 avatar meghe2000 commented on June 3, 2024

I conducted a new review and realized that when I add this code to my project, this issue arises. I need the functions with the same name.

Array.prototype.remove = function (item) { return this.splice(this.indexOf(item), 1) }
Array.prototype.insert = function (index) { this.splice.apply(this, [index, 0].concat(Array.prototype.slice.call(arguments, 1))); return this; }

from pixijs.

bigtimebuddy avatar bigtimebuddy commented on June 3, 2024

In general, adding prototype methods to global objects is not a good practice. It can lead to issues such as this, where we are doing a for-loop and it picks up these methods as enumerable. We see this sometimes with Object.prototype method because we often enumerate through the keys. The best solution is to create utility methods (e.g., ArrayUtils.remove(arr, item)). If you are going to add prototype chain methods, make sure they are not enumerable like this:

Object.defineProperties(Array.prototype, {
  remove: {
    enumerable: false,
    get(item) {
      return this.splice(this.indexOf(item), 1);
    }
  }
});

from pixijs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.