On 17 March 2017 at 08:03, Ben Newman <[email protected]> wrote:
> Just to check my understanding, would
>
>   Boolean.parseBoolean = function (value) {
>     return !! (value && JSON.parse(String(value)));
>   };
>
> be a reasonable polyfill for your proposed function?

Not quite -- that would throw for strings that are not valid JSON, e.g.:

```
Boolean.parseBoolean('{dddddd]');
```

It'd probably be more like:

```
Boolean.parseBoolean = function (val) {
  if (val === 'false') return false;
  return !!val;
};
```

-- 
- Karl Cheng (Qantas94Heavy)
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to