V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
123s
V2EX  ›  程序员

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

  •  
  •   123s · 2016-01-13 14:22:18 +08:00 · 6866 次点击
    这是一个创建于 3024 天前的主题,其中的信息可能已经有所发展或是发生改变。
    3 条回复    2016-01-13 15:52:38 +08:00
    SpicyCat
        1
    SpicyCat  
       2016-01-13 15:42:52 +08:00   ❤️ 1
    > 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
        2
    123s  
    OP
       2016-01-13 15:44:44 +08:00
    @SpicyCat 长知识了
    sensui7
        3
    sensui7  
       2016-01-13 15:52:38 +08:00
    shim 和 sham 就是 i 和 a 的区别,

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

    逃..
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1260 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 23:28 · PVG 07:28 · LAX 16:28 · JFK 19:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.