Skip to content

Improved guide instance.md examples #1458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 2, 2018
Merged

Conversation

fenekku
Copy link
Contributor

@fenekku fenekku commented Feb 26, 2018

I was going through the guide to learn Vuejs and was confused by 2 of the examples that turned out not to work. I corrected them here (I hope ;) ).

  • Made some examples stronger by making sure that if their corresponding statements were false, the examples would indeed pick up on it:
    • comparing integers will not highlight that they are the integers from the same location in memory
    • fixed the freeze example such that if commented it out, it would work

- Made some examples stronger by making sure that if their corresponding statements were false, the examples would indeed pick up on it:
  * comparing integers will not highlight that they are the integers from the same location in memory
  * fixed the freeze example such that if commented it out, it would work
@chrisvfritz
Copy link
Contributor

chrisvfritz commented Feb 27, 2018

@fenekku Thanks! Here are my thoughts:

comparing integers will not highlight that they are the integers from the same location in memory

I worry this example is actually more confusing (and contrived, as we would probably never assign a number to a property that previously held an object). We also demonstrate adding a new b property later, which is unrelated to this original property. Finally, it's not an area where we've noticed confusion in the past, so I'm hesitant to make it more complex.

fixed the freeze example such that if commented it out, it would work

Can you explain more about what you mean here? In the current example, commenting out the Object.freeze would indeed work.

@fenekku
Copy link
Contributor Author

fenekku commented Feb 28, 2018

Thanks for the comments! Here are my thoughts:

Finally, it's not an area where we've noticed confusion in the past, so I'm hesitant to change make it more complex.

Haha well I was confused by it ;) . More to the point, should we remove:

// These reference the same object!
vm.a === data.a // => true

then? Or maybe rephrase it (see below). My main problem is that using the above === equality, with a being an integer, does not prove that vm and data point to the same object (even less that vm.a and data.a point to the same object since a is not an object). Maybe we can have the following:

// Getting the property from the instance
// returns the one from the original data
vm.a == data.a // => true

What I like about this approach is 1) solves our above problem 2) uses the word getting and since setting is mentioned later this builds up to the setters/getters concept. I changed the commit to this.

In the current example, commenting out the Object.freeze would indeed work.

My mistake, you are absolutely right! Because I wasn't familiar with the data() { } syntax as opposed to the data: {} syntax that was used up until now (and forgot the object destructuring syntax), I had changed the syntax of the example and was getting obj not defined. Maybe introducing the data() { } syntax before using it for the first time in this example would remove a confusion point. I left the commit as is, but I can change it if need be.

@chrisvfritz
Copy link
Contributor

I like it! Thanks for the improvement. 🙂

@chrisvfritz chrisvfritz merged commit d18b30c into vuejs:master Mar 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants