The closest you can get to DEstructuring assignmeNT with good old ES5's objects and functions.
dent
for arrays:
> var tuple = ['first', 'second', 'third']
> dent(tuple)
> var a = dent() // Or in a single statement: dent(tuple)()
> var b = dent()
> var c = dent()
> dent.idx
3 // Next element's index.
> [a, b, c]
[ 'first', 'second', 'third' ]
dent
for objects:
> var pair = { first: 'foo', second: 'bar' }
> dent(pair)
> var a = dent.o.first // Or in a single statement: dent(pair).o.first
> var b = dent.o.second
> [a, b]
[ 'foo', 'bar' ]
Save reference to obj
in dent.o
. Return the dent
itself.
Object passed to dent
the last time.
Return the next element (with index dent.idx
) and increment dent.idx
by 1.
Next element's index (as would be accessed by dent()
).
dent
storage is temporary. Drop your object in, take it apart, but don't assume that it will sit in dent.o
or dent.idx
will be the same next time you check.
npm install dent
MIT