JS Types to Avoid Polyfilling

I was reading the AirBnB JavaScript Style Guide recently and came across:

“Symbols and BigInts cannot be faithfully polyfilled, so they should not be used when targeting browsers/environments that don’t support them natively.”

Since I didn’t know …


This content originally appeared on DEV Community and was authored by Lucia Cerchie

I was reading the AirBnB JavaScript Style Guide recently and came across:

"Symbols and BigInts cannot be faithfully polyfilled, so they should not be used when targeting browsers/environments that don’t support them natively."

Since I didn't know what polyfilling was, I couldn't understand the full implication of the rest of the sentence.

Wikipedia provided a helpful definition:

"In web development, a polyfill is code that implements a feature on web browsers that do not support the feature."

Ok, so that was polyfilling in theory -- using code to patch discrepancies between browsers. But what about in practice? And why doesn't it work for Symbols and BigInts? I decided to hunt down a good example.

I found a great one on Javascript.info. It explained that the Math.trunc() function doesn't exist in all JS engines, so the polyfill code for it checks for the built-in func, and if it doesn't exist, executes the same functionality.

I found the exact reason why polyfilling is not a wise idea for BigInt on JavaScript.info as well:

"To emulate such behavior, a polyfill would need to analyze the code and replace all such operators with its functions. But doing so is cumbersome and would cost a lot of performance."

But what about Symbols? I found the definition of the Symbol type on MDN:

"Symbol is a built-in object whose constructor returns a symbol primitive — also called a Symbol value or just a Symbol — that’s guaranteed to be unique."

Because these values must be guaranteed to be unique, I can imagine the process to generate them with a polyfill must also be high performance, like that of generating BigInts. That's my surmise, but I was unable to find anything that supported it, so I'd appreciate input here!

The last question I have is:

Why does the AirBnB style guide say Symbols and BigInts cannot be faithfully polyfilled? It seems that they can't be frugally polyfilled, in terms of performance, but I wonder why they used the adjective "faithfully". Does it mean that polyfilling these types changes them in some way?


This content originally appeared on DEV Community and was authored by Lucia Cerchie


Print Share Comment Cite Upload Translate Updates
APA

Lucia Cerchie | Sciencx (2021-12-29T22:28:28+00:00) JS Types to Avoid Polyfilling. Retrieved from https://www.scien.cx/2021/12/29/js-types-to-avoid-polyfilling/

MLA
" » JS Types to Avoid Polyfilling." Lucia Cerchie | Sciencx - Wednesday December 29, 2021, https://www.scien.cx/2021/12/29/js-types-to-avoid-polyfilling/
HARVARD
Lucia Cerchie | Sciencx Wednesday December 29, 2021 » JS Types to Avoid Polyfilling., viewed ,<https://www.scien.cx/2021/12/29/js-types-to-avoid-polyfilling/>
VANCOUVER
Lucia Cerchie | Sciencx - » JS Types to Avoid Polyfilling. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/12/29/js-types-to-avoid-polyfilling/
CHICAGO
" » JS Types to Avoid Polyfilling." Lucia Cerchie | Sciencx - Accessed . https://www.scien.cx/2021/12/29/js-types-to-avoid-polyfilling/
IEEE
" » JS Types to Avoid Polyfilling." Lucia Cerchie | Sciencx [Online]. Available: https://www.scien.cx/2021/12/29/js-types-to-avoid-polyfilling/. [Accessed: ]
rf:citation
» JS Types to Avoid Polyfilling | Lucia Cerchie | Sciencx | https://www.scien.cx/2021/12/29/js-types-to-avoid-polyfilling/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.