Re: [whatwg/dom] Consider boolean interface for properties (#461)

There's a parallel world about special attributes exposed through JS via DOM, one is the real hook, usually an accessor in the prototype, and another one is the HTML facade.

My way to understand if a property should be set through `node.setAttribute(key, value)` rather than `node[key] = value;` is to simply feature-detect `key in node ? (node[key] = value) : node.setAttribute(key, value);`.

This works for 99% of special properties, including DOM Level 0 events, but it fails with special attributes like `style`, so far the only one I know, because you cannot `node.style = blah` directly, that's a special setter.

To give you a better understanding of how attributes VS accessors work, check the following example:
```js
document.body.innerHTML = '<input value="123">';
var input = document.body.firstElementChild;

// fallback to attribute
input.value; // 123

// same as
input.getAttribute('value'); // 123

// but look at the screen now ...
input.value = 456;

// there you go, still 123
input.getAttribute('value'); // 123

// outerHTML? Same
input.outerHTML; // <input value="123">

// but what will be submitted ?
input.value; // 456
```

The boolean case is an extra exception to the rule: is it `true` ? Attribute will be there, otherwise it won't.

```js
document.body.innerHTML = '<input value="123">';
var input = document.body.firstElementChild;
input.disabled = true;

// and here the outcome
input.outerHTML; // <input value="123" disabled="">
```

In this case it's just about having such attribute, but it's value is important too.

For strictly boolean defined attributes the value is not relevant, the `boolean` value is define by the presence of such attribute, no matter what's the value!

**However** there are cases where boolean presence can have also meaningful values, which is a whole new world of possibilities.

This is the case of the `crossorigin` [attribute](https://jakearchibald.com/2017/es-modules-in-browsers/#no-credentials), which has a boolean meaning (is it there or not?) and also a possible meaningful value such `use-credentials`.

Here the logic to whatever standard proposal should consider the ability to pass a non boolean, reflected, value.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/461#issuecomment-303239277

Received on Monday, 22 May 2017 22:40:24 UTC