jonathantneal / polyfill

A polyfill combinator
MIT License
738 stars 13 forks source link

Always do a test to see if the polyfilled property exists natively #59

Closed wheresrhys closed 9 years ago

wheresrhys commented 10 years ago

i.e each polyfill should start off with e.g.

TheThing.TheMethod = TheThing.TheMethod || function () { 
// the polyfill
};

It makes sense to err on the side of caution for two reasons:

  1. If your ua-features map gets out of date (realistically this is going to happen often, even if only for short time periods) it means native code will be favoured over the polyfill, which will mean the code executes faster
  2. When requesting all polyfills (e.g. as I'm doing for testing in phantomjs) it will always default to native code
jonathantneal commented 10 years ago

@wheresrhys, please see #43. This addresses when and how polyfills are added and why certain ones would not check for existing functionality. This is really key to how things work. The restructure branch is where feature tests are added.

wheresrhys commented 10 years ago

I see. That definitely seems sensible.

triblondon commented 10 years ago

The FT fork of the service does not recognise the differences between different types of polyfill and offers feature detection for all of them.