55

What is the difference between a shim an a sham?

Is it enough to include es5-shim.min.js and es6-shim.min.js or should I also include es5-sham.min.js and es6-sham.min.js?

garbanzio
  • 846
  • 1
  • 7
  • 10
  • 1
    I would like to be able to blindly support as many ES5 and ES6 features as possible in all browsers. Is that more helpful? – garbanzio Dec 16 '14 at 16:12
  • @garbanzio: I don't think that's a sensible approach. You won't be able to use all features blindly (as not all of them can be emulated), so you'll have to check for each feature anyway. And when you do that you might as well decide if you need the shams or not. – Joachim Sauer Dec 16 '14 at 16:21

1 Answers1

44

According to this Github page the shims include all monkey-patches that faithfully represent the ES5 features.

In other words: you can use the features provided by these files as if you were using ES5 proper.

The shams, however contain those features that can not be emulated with other code. They basically provide the API, so your code doesn't crash but they don't provide the actual functionality.

Which ones do you need? That depends on how you write your code. If you only use features provided by the shims, then include that. If you also want to (optionally) use features from the shams, then you need both of them.

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
  • 2
    The [Wikipedia page on polyfills](http://en.wikipedia.org/wiki/Polyfill#es5-shim) describes it in a pretty succinct fashion as well. – hon2a Dec 16 '14 at 16:11
  • 1
    Thanks. Here is what I gather from the two sources mentioned above: From ES5 github repo... "In many cases, this means that these shams cause many ES5 methods to silently fail. Decide carefully whether this is what you want." From wikipedia... "es5-sham.js contains partial implementations of the other methods which rely too much on the underlying engine to work accurately." I can also see which features are supported by the sham/shim in the repo. What would be even more helpful, is if someone knows which features normally supported by the shim will break when adding the sham. – garbanzio Dec 16 '14 at 16:22
  • 2
    I haven't tried that specifically, but if anything in the shams broke anything in the shims I'd consider that a bug. – Joachim Sauer Dec 16 '14 at 16:24