Digital Office Automation System
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 天之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. `es5-shim.js` and `es5-shim.min.js` monkey-patch a JavaScript context to
  2. contain all EcmaScript 5 methods that can be faithfully emulated with a
  3. legacy JavaScript engine.
  4. `es5-sham.js` and `es5-sham.min.js` monkey-patch other ES5 methods as
  5. closely as possible. For these methods, as closely as possible to ES5
  6. is not very close. Many of these shams are intended only to allow code
  7. to be written to ES5 without causing run-time errors in older engines.
  8. In many cases, this means that these shams cause many ES5 methods to
  9. silently fail. Decide carefully whether this is what you want.
  10. ## Tests
  11. The tests are written with the Jasmine BDD test framework.
  12. To run the tests, navigate to <root-folder>/tests/.
  13. In order to run against the shim-code, the tests attempt to kill the current
  14. implementation of the missing methods. This happens in <root-folder>/tests/helpers/h-kill.js.
  15. So in order to run the tests against the built-in methods, invalidate that file somehow
  16. (comment-out, delete the file, delete the script-tag, etc.).
  17. ## Shims
  18. ### Complete tests ###
  19. * Array.prototype.every
  20. * Array.prototype.filter
  21. * Array.prototype.forEach
  22. * Array.prototype.indexOf
  23. * Array.prototype.lastIndexOf
  24. * Array.prototype.map
  25. * Array.prototype.some
  26. * Array.prototype.reduce
  27. * Array.prototype.reduceRight
  28. * Array.isArray
  29. * Date.now
  30. * Date.prototype.toJSON
  31. * Function.prototype.bind
  32. * /!\ Caveat: the bound function's length is always 0.
  33. * /!\ Caveat: the bound function has a prototype property.
  34. * /!\ Caveat: bound functions do not try too hard to keep you
  35. from manipulating their ``arguments`` and ``caller`` properties.
  36. * /!\ Caveat: bound functions don't have checks in ``call`` and
  37. ``apply`` to avoid executing as a constructor.
  38. * Object.keys
  39. * String.prototype.trim
  40. ### Untested ###
  41. * Date.parse (for ISO parsing)
  42. * Date.prototype.toISOString
  43. ## Shams
  44. * /?\ Object.create
  45. For the case of simply "begetting" an object that
  46. inherits prototypically from another, this should work
  47. fine across legacy engines.
  48. /!\ Object.create(null) will work only in browsers that
  49. support prototype assignment. This creates an object
  50. that does not have any properties inherited from
  51. Object.prototype. It will silently fail otherwise.
  52. /!\ The second argument is passed to
  53. Object.defineProperties which will probably fail
  54. silently.
  55. * /?\ Object.getPrototypeOf
  56. This will return "undefined" in some cases. It uses
  57. __proto__ if it's available. Failing that, it uses
  58. constructor.prototype, which depends on the constructor
  59. property of the object's prototype having not been
  60. replaced. If your object was created like this, it
  61. won't work:
  62. function Foo() {
  63. }
  64. Foo.prototype = {};
  65. Because the prototype reassignment destroys the
  66. constructor property.
  67. This will work for all objects that were created using
  68. `Object.create` implemented with this library.
  69. * /!\ Object.getOwnPropertyNames
  70. This method uses Object.keys, so it will not be accurate
  71. on legacy engines.
  72. * Object.isSealed
  73. Returns "false" in all legacy engines for all objects,
  74. which is conveniently guaranteed to be accurate.
  75. * Object.isFrozen
  76. Returns "false" in all legacy engines for all objects,
  77. which is conveniently guaranteed to be accurate.
  78. * Object.isExtensible
  79. Works like a charm, by trying very hard to extend the
  80. object then redacting the extension.
  81. ### Fail silently
  82. * /!\ Object.getOwnPropertyDescriptor
  83. The behavior of this shim does not conform to ES5. It
  84. should probably not be used at this time, until its
  85. behavior has been reviewed and been confirmed to be
  86. useful in legacy engines.
  87. * /!\ Object.defineProperty
  88. This method will silently fail to set "writable",
  89. "enumerable", and "configurable" properties.
  90. Providing a getter or setter with "get" or "set" on a
  91. descriptor will silently fail on engines that lack
  92. "__defineGetter__" and "__defineSetter__", which include
  93. all versions of IE up to version 8 so far.
  94. IE 8 provides a version of this method but it only works
  95. on DOM objects. Thus, the shim will not get installed
  96. and attempts to set "value" properties will fail
  97. silently on non-DOM objects.
  98. https://github.com/kriskowal/es5-shim/issues#issue/5
  99. * /!\ Object.defineProperties
  100. This uses the Object.defineProperty shim
  101. * Object.seal
  102. Silently fails on all legacy engines. This should be
  103. fine unless you are depending on the safety and security
  104. provisions of this method, which you cannot possibly
  105. obtain in legacy engines.
  106. * Object.freeze
  107. Silently fails on all legacy engines. This should be
  108. fine unless you are depending on the safety and security
  109. provisions of this method, which you cannot possibly
  110. obtain in legacy engines.
  111. * Object.preventExtensions
  112. Silently fails on all legacy engines. This should be
  113. fine unless you are depending on the safety and security
  114. provisions of this method, which you cannot possibly
  115. obtain in legacy engines.