Re: Removing the concept of "optional any"

On Wed, Feb 19, 2014 at 1:36 PM, Domenic Denicola
<domenic@domenicdenicola.com> wrote:
>
> From: Jonas Sicking <jonas@sicking.cc>
>
>>I can both see the argument "if you were to naively implement this in JS omitting x should be equivalent to x === undefined" and "omitting x is clearly a bug, throw an exception".
>
> I'm trying to understand the specific use case here. Why would passing `undefined` not be "clearly a bug"? Is it because `undefined` is a valid message to post?

Yes.

> In that case, if I were a JS programmer trying to post a message of `undefined`, I would do so by doing `postMessage()`, not `postMessage(undefined)`.

That seems exceedingly awkward. Consider

function processWork(data) {
  if (data === undefined) {
    worker.postMessage();
  } else {
    worker.postMessage(data);
  }
}

vs.

function processWork(data) {
  worker.postMessage(data);
}

/ Jonas

Received on Wednesday, 19 February 2014 22:22:47 UTC