Wednesday, 21 August 2019

Cannot bind Javascript Symbol to HTMLElement.style

Why I can bind a Javascript Symbol to anything else but a style of an HTMLElement?

https://jsfiddle.net/elgs/ftj9zx42/3/

Here's the HTML:

<div id='a'></div>

Here's the Javascript:

const a = document.querySelector('#a');
a.classList._someSymbol = Symbol('some_symbol');
console.log(1);
a.style._someSymbol = Symbol('some_symbol');
console.log(2);

And here's the output:

1
(index):35 Uncaught TypeError: Cannot convert a Symbol value to a string
    at window.onload ((index):35)

Update:

The whole story is I'm writing a proxy that will attach a Symbol to every property as identifier in the get trap, this unintentionally included the style. I will eventually include only the properties that I'm interested in, that won't include the style. But now I got this error and I'm curious why this happened.



from Cannot bind Javascript Symbol to HTMLElement.style

No comments:

Post a Comment