W3C home > Mailing lists > Public > public-script-coord@w3.org > July to September 2013

Re: How to specify an object that can be mutable or immutable

From: Domenic Denicola <domenic@domenicdenicola.com>
Date: Thu, 26 Sep 2013 13:35:54 +0000
To: Dirk Schulze <dschulze@adobe.com>
CC: Simon Pieters <simonp@opera.com>, "robert@ocallahan.org" <robert@ocallahan.org>, "public-script-coord@w3.org" <public-script-coord@w3.org>
Message-ID: <5DB3C392-EF43-47A4-A6C9-B0ADDDDCF4FA@domenicdenicola.com>
> Hmm, then every method that can take both as argument, also must specify both every time. Beside that, you also need to implement each interface twice. One for the mutable case, on for the immutable. Means you have duplication all over the platform. That sound suboptimal.

Shouldn't any interfaces that take these as arguments actually accept anything in the form { left, right, top, bottom } or { left, right, width, height }? No real JS API would force you to pass through a constructor when an object literal would do.

Stated in terms of proto-JSIDL semantics (which admittedly are not a real thing yet), for arguments you would not use the DOMRect brand, but instead the ToRect conversion, which takes objects of the above two forms and returns a normalized version for your method's algorithm to operate on (or throws a TypeError if the incoming object does not match either of those two forms).

DOMRect still has use as a return value, and DOMRect instances pass through ToRect just fine, but using DOMRect on the input side as well as for return values makes for very awkward APIs, of the type this mailing list is designed to help avoid.
Received on Thursday, 26 September 2013 13:36:28 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:14:18 UTC