Subscribe on changes!

Object.prototype do not work correctly

avatar
Aug 9th 2021

Version

3.2.0-beta.8

Reproduction link

https://codesandbox.io/s/frosty-sun-471ok?file=/src/main.js

Steps to reproduce

look console.log

What is expected?

get value

What is actually happening?

not get value

avatar
Aug 9th 2021

Use this: https://v3.vuejs.org/api/application-config.html#globalproperties


Please, next time consider using the forum, the Discord server or StackOverflow for questions first. But feel free to come back and open an issue if it turns out to be a bug 🙂

avatar
Aug 16th 2021

https://codesandbox.io/s/frosty-sun-471ok?file=/src/main.js please look at the code again, thanks @posva Is this intentional? we can't use Object.prototype with vue together?

avatar
Aug 16th 2021

use Object.defineProperty to define the property on the prototype.

avatar
Aug 16th 2021

use Object.defineProperty to define the property on the prototype.

It does work but why, use Object.propotype will error is it a bug?

avatar
Aug 16th 2021

you are adding a property to all objects, it is possible that you broke code that did not expect to have that property there.

avatar
Aug 17th 2021

@posva is this a bug? Can you reconsider reopen ? thank you

avatar
Aug 17th 2021

I don't think this is a bug because extending Object.prototype should be avoided at all costs. It will break any library that iterates through keys with for in, which can be used for performance reasons.

avatar
Aug 17th 2021

This is not considered a bug because mutating Object.prototype is something you should never do in modern JavaScript. While Vue 3 can go out of its way to "support" it, it just incurs performance overhead on all other users (99.9%) for a case where there is no actual benefits.

https://github.com/vuejs/vue-next/pull/4361#issuecomment-900430368