On 2/21/16 11:01 AM, Jan-Ivar Bruaroey wrote:
> On 2/20/16 2:36 AM, Peter Thatcher wrote:
>> So how are we better off with an enum in this case?
>
> Because there's precedent for expecting undefined to be interpreted as
> false [1], and no such precedent for strings?
For example, imagine this code in your company's source tree written by
someone else:
function foo(label, ordered) {
pc.createDataChannel(label, {ordered: ordered ? true : false });
}
then someone touching that area might feel compelled optimize it to:
function foo(label, ordered) {
pc.createDataChannel(label, {ordered: ordered });
}
except today they'll unwittingly have introduced a bug, because
elsewhere in the tree people readily expect these two calls to mean the
same:
foo("label", false);
foo("label");
and in the second case, the person touching the code will have subtly
changed data channels to be ordered, which was not their intent.
If instead the code looked like this:
function foo(label, ordered) {
pc.createDataChannel(label, {ordered: ordered ? "ordered" :
"unordered" });
}
then there is no obvious optimization.
.: Jan-Ivar :.