Skip to content
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

The Caveats2 in List Rendering, example1.items.splice function can't achive as exprected in some cases #963

Closed
aswind7 opened this issue Jun 19, 2017 · 1 comment

Comments

@aswind7
Copy link

aswind7 commented Jun 19, 2017

When you modify the length of the array, e.g. vm.items.length = newLength

To deal with caveat 2, you can also use splice:
example1.items.splice(newLength)

But when the newLength Is greater than the current length, this methods failure.
for example

qq20170619-095112 2x

@chrisvfritz
Copy link
Contributor

chrisvfritz commented Jun 21, 2017

I just update the docs to remove the also in you can also use splice. Hopefully, this makes it clearer that we recommend splice as an alternative to directly setting the length of an array.

As an aside, I don't actually recommend setting length to increase the size of an array in JavaScript. What you get at the end is not actually an array with 8 indices pointing to the value undefined, as it would appear, but rather 8 indices with undefined pointers. The difference is subtle, but has important implications. For example, if you try to map over this array with a.map(() => 3), what you'll get is [3, 3, undefined x 8], rather than [3, 3, 3, 3, 3, 3, 3, 3, 3, 3] as you might expect.

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

No branches or pull requests

2 participants