Re: Is polyfilling future web APIs a good idea?

On Thu, Aug 6, 2015 at 6:50 PM, Glen Huang <curvedmark@gmail.com> wrote:
> @William @Matthew
>
> Ah, thanks. Now I think prollyfill is prolly a good name. :)
>
> @Brian
>
> Actually, I had this pattern in mind:
>
> When no browsers ship the API:
>
> ```
> if (HTMLElement.prototype.foo) {
>   HTMLElement.prototype._foo = HTMLElement.prototype.foo;
> } else {
>   HTMLElement.prototype._foo = polyfill;
> };
> ```

This assumes you'll match, which - again depending on how far you are
might be a big bet... Personally, I wouldn't use that myself if
writing something -- Seems a lot like  when people simply provided N
versions of the same prefixed properties instead of just one, it has
potential to go awry... No one can actually vary because they've done
the equivalent of shipping the unprefixed thing inadvertently
intending it to be an experiment, but it wasnt.

>
> When at least two browsers ship this API:
>
> ```
> if (!HTMLElement.prototype.foo) {
>  HTMLElement.prototype.foo = polyfill;
> }
> HTMLElement.prototype._foo = function() {
>   console.warn("deprecated");
>   return this.foo();
> };
> ```

But it's not deprecated in browsers that don't support it, it's a
polyfill at that point and aside from the console.warn (which again,
in this case seems incorrect in the message at least) it should be
generally be identical to the oneliner I gave before - the prototype
for _foo is the polyfill version.



-- 
Brian Kardell :: @briankardell :: hitchjs.com

Received on Thursday, 6 August 2015 23:08:04 UTC