- From: Domenic Denicola <domenic@domenicdenicola.com>
- Date: Fri, 13 Sep 2013 19:19:04 +0000
- To: Boris Zbarsky <bzbarsky@MIT.EDU>
- CC: Anne van Kesteren <annevk@annevk.nl>, WebApps WG <public-webapps@w3.org>
From: Boris Zbarsky [mailto:bzbarsky@MIT.EDU] > Consider this IDL: > > dictionary Dict1 { > long a = 5; > }; > > dictionary Dict2 { > sequence<Dict1> dicts; > } > > void foo(optional Dict2 arg); > > How would you express eqivalent semantics with destructuring? ```js function foo({ dicts: [...dict1s] } = undefined) { } ``` gets pretty close. (`= undefined` is unnecessary, of course, but I include it for clarity.) All that remains is some kind of annotation to ensure that every element of `dict1s` also gets destructured as `let { a } = dict1s[0]` etc., and then type coercion `let numberA = Number(a)`. > How does destructuring take care of making sure that arg.dicts is a new array? As you can see this is taken care of. > How does it ensure arg.dicts[0] is a new object with an "a" property, not whatever was passed in? Indeed, there is no way to set up a destructuring pattern for every element in a sequence, but destructuring is still the approach you will want to use, i.e. `let { a } = dict1s[i]` in a loop. > And in any case it does not do any coercion on arg.dicts[0].a. Indeed, I think we've said a few times in this thread that the biggest piece any IDL needs that is not provided by JS is type coercions.
Received on Friday, 13 September 2013 19:19:50 UTC