JavaScript overwrite prototype method

Consider the following code:

class X {
  pop() { return 'ORIGINAL'; }
}

const x = new X();

x.pop(); // 'ORIGINAL' via prototype lookup

x.pop = () => 'NEW'; // install a new pop()

x.pop(); // 'NEW' calls x's pop()

Object.getOwnPropertyDescriptors(x); // has NEW pop
Object.getOwnPropertyDescriptors(Object.getPrototypeOf(x)); // has ORIGINAL pop

When calling pop, prototype lookup finds the ORIGINAL pop. Why does assignment not overwrite that one instead of installing NEW pop on x?

It works if I do X.prototype.pop = () => 'NEW'; explicitly.

138 thoughts on “JavaScript overwrite prototype method”

  1. Howdy just wanted to give you a quick heads up. The text in your post
    seem to be running off the screen in Chrome. I’m not
    sure if this is a format issue or something to do with browser compatibility but
    I figured I’d post to let you know. The design and style look great though!
    Hope you get the problem fixed soon. Kudos

    Reply
  2. I have been surfing on-line greater than three hours as of late, yet I by no means discovered any fascinating article like yours.
    It is lovely worth sufficient for me. In my view,
    if all webmasters and bloggers made just right content material as you
    probably did, the web will probably be much more useful than ever before.

    Reply
  3. Its such as you learn my thoughts! You seem to grasp so much approximately this, like you wrote
    the book in it or something. I believe that you just could do with some p.c.
    to force the message house a little bit, however other than that, that is excellent blog.
    An excellent read. I’ll certainly be back.

    Reply
  4. Hello just wanted to give you a quick heads up.

    The text in your content seem to be running off the screen in Chrome.
    I’m not sure if this is a format issue or something to do with web browser compatibility but I figured I’d post to let
    you know. The style and design look great though! Hope you get the problem fixed
    soon. Thanks

    Reply
  5. I’ll right away grab your rss feed as I can’t find your email subscription hyperlink or newsletter service.
    Do you have any? Please permit me recognize in order that I may subscribe.
    Thanks.

    Reply
  6. Great – I should certainly pronounce, impressed with your site. I had no trouble navigating through all the tabs and related info ended up being truly easy to do to access. I recently found what I hoped for before you know it at all. Quite unusual. Is likely to appreciate it for those who add forums or anything, site theme . a tones way for your customer to communicate. Nice task.

    Reply
  7. I truly love your site.. Great colors & theme. Did you create this website yourself?
    Please reply back as I’m attempting to create my own website
    and want to know where you got this from or just what the
    theme is called. Kudos!

    Reply
  8. Hi would you mind letting me know which hosting
    company you’re using? I’ve loaded your blog in 3 different
    browsers and I must say this blog loads a lot quicker then most.

    Can you suggest a good web hosting provider at a reasonable price?

    Many thanks, I appreciate it!

    Reply
  9. It’s perfect time to make some plans for the longer term and it is time
    to be happy. I’ve learn this post and if I could I wish to counsel you few interesting things or suggestions.
    Perhaps you could write subsequent articles regarding this article.

    I wish to learn more issues approximately it!

    Reply
  10. I have been surfing on-line greater than three hours these days,
    yet I by no means found any fascinating article
    like yours. It is lovely value sufficient for me.
    In my opinion, if all website owners and bloggers made good content
    as you did, the internet will probably be much more helpful than ever before.

    Reply
  11. Pingback: sildenafil
  12. Pingback: canadian viagra
  13. I’m not sure exactly why but this weblog is loading incredibly
    slow for me. Is anyone else having this issue or is it a
    problem on my end? I’ll check back later and see if the problem still exists.

    Reply
  14. It’s appropriate time to make some plans for the future and it
    is time to be happy. I’ve read this post and if I could I want to suggest you few interesting
    things or tips. Maybe you can write next articles referring to this article.
    I desire to read more things about it!

    Reply
  15. Hey just wanted to give you a quick heads up. The text in your content seem to be running
    off the screen in Internet explorer. I’m not sure if this is a format issue or something to
    do with web browser compatibility but I thought I’d post
    to let you know. The design look great though!
    Hope you get the issue resolved soon. Cheers

    Reply
  16. Pingback: cialis alternative
  17. Pingback: sildenafil 6mg
  18. It is perfect time to make some plans for the future and it’s time to be happy.

    I’ve read this post and if I could I want to suggest you few interesting things or advice.
    Perhaps you could write next articles referring to this article.
    I desire to read more things about it!

    Reply
  19. Pingback: cialis free sample
  20. Pingback: sildenafil citrate
  21. Pingback: viagra tabs
  22. Pingback: ivermectay 6 mg
  23. Pingback: sildenafil walmart
  24. Pingback: women viagra
  25. Pingback: bestellen viagra
  26. Pingback: viagra walmart
  27. Pingback: viagra vs.levitra
  28. Pingback: walgreens viagra
  29. Pingback: roman sildenafil
  30. Pingback: ivermectin 8 mg
  31. Pingback: médicament cialis
  32. Pingback: ivermectin gf213

Leave a Comment