Take off this restriction would increase the consistency.
I understand that every component needs a copy of the data object.
But can't you just copy the data object under the hood? Are there any benefits by using a function instead?
Vue.component('foo', {
data: {
foo: 'bar'
}
});
This is a technical restriction due to javascript
@posva
Can you tell me what exactly the technical restriction it is...?
It's because in js objects are references, please, ask questions on the forums or discord server 🙂
But can't you just copy the data object under the hood? Are there any benefits by using a function instead?
Deep cloning objects (copy the data object under the hood) causes 1). heavy performance overhead 2). bloated code for a deep clone implementation. So it's better to just use a function to create a fresh object every time.
@posva
Thanks :)
Yes, but I mean can't we just use Object.assign to clone the data object..?
Object.assign is not deep
Most helpful comment
Deep cloning objects (copy the data object under the hood) causes 1). heavy performance overhead 2). bloated code for a deep clone implementation. So it's better to just use a function to create a fresh object every time.