mutant icon indicating copy to clipboard operation
mutant copied to clipboard

Array().length == 1?

Open arj03 opened this issue 7 years ago • 2 comments

It seems that

let a = Array()
console.log(a.length)

= 1, but:

let a2 = []
console.log(a2.length)

= 0

This is a bit of a gotcha :)

arj03 avatar Oct 28 '17 19:10 arj03

Indeed. This is one of the many unfortunate consequences of using function as the base for all the observables.

Here is an idea to improve the situation by making only the simple types based on function and moving the complex (collections, structs, etc) to ordinary objects: https://github.com/mmckegg/mutant/issues/8#issuecomment-320532689

We’d also change isObservable to use Symbols for detection instead of typeof x === ‘function’.

mmckegg avatar Oct 28 '17 21:10 mmckegg

Great! I'm all for removing gotcha's. This is very much related to the documentation part of scuttlebot. While developing something for patchcore I changed my tactics to highlightning pain points I find as I move through them, hopefully we can all learn something :)

arj03 avatar Oct 30 '17 07:10 arj03