求长知识, shim 和 sham 什么区别

2016-01-13 14:22:18 +08:00
 123s
http://stackoverflow.com/questions/27508833/shim-vs-sham-what-is-the-difference
英文太弱,理解不了。
6885 次点击
所在节点    程序员
3 条回复
SpicyCat
2016-01-13 15:42:52 +08:00
> es5-shim.js and es5-shim.min.js monkey-patch a JavaScript context to contain all EcmaScript 5 methods that can be faithfully emulated with a legacy JavaScript engine.
shim 完美模拟了所有 ES5 中可以被完美模拟的方法。有点绕,就是说 ES5 中有些方法,是可以在旧 JS 引擎中完美模拟了,那么 shim 就完美模拟了它们。

> es5-sham.js and es5-sham.min.js monkey-patch other ES5 methods as closely as possible. For these methods, as closely as possible to ES5 is not very close. Many of these shams are intended only to allow code to be written to ES5 without causing run-time errors in older engines. In many cases, this means that these shams cause many ES5 methods to silently fail. Decide carefully whether this is what you want. Note: es5-sham.js requires es5-shim.js to be able to work properly.
这一段别看这么多,核心意思就是 ES5 中其他无法被完美模拟的方法,就由 sham 承包了。 sham 只承诺你用的时候代码不会崩溃,至于对应的方法是不是起作用它就不保证了,它只是尽力模拟(as close as possible)

所以如果你要用的方法在 shim 中都包含了,那么就不需要 sham 。 sham 能不引用就不引用。但是如果你要用的方法只包含在 sham 中,那你要明白 sham 只是保证不崩溃,并不能保证对应方法的功能正确。
另外 sham 依赖 shim
123s
2016-01-13 15:44:44 +08:00
@SpicyCat 长知识了
sensui7
2016-01-13 15:52:38 +08:00
shim 和 sham 就是 i 和 a 的区别,

I = 我, a = 俺, 显然 我 包含了 俺, 而 俺 不一定与 我 相等.

逃..

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/250434

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX