Object.prototype do not work correctly
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
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 🙂
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?
use
Object.defineProperty
to define the property on the prototype.
It does work but why, use Object.propotype will error is it a bug?
you are adding a property to all objects, it is possible that you broke code that did not expect to have that property there.
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.
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