Blame view

node_modules/es5-shim/README.md 6.58 KB
2a09d1a4   liuqimichale   添加宜春 天水 宣化
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
  # es5-shim <sup>[![Version Badge][npm-version-svg]][npm-url]</sup>
  
  [![npm badge][npm-badge-png]][npm-url]
  
  [![Build Status][travis-svg]][travis-url]
  [![dependency status][deps-svg]][deps-url]
  [![dev dependency status][dev-deps-svg]][dev-deps-url]
  
  `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.
  **Note:** As `es5-shim.js` is designed to patch the native Javascript
  engine, it should be the library that is loaded first.
  
  `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.
  
  
  ## Tests
  
  The tests are written with the Jasmine BDD test framework.
  To run the tests, navigate to <root-folder>/tests/ , or,
  simply `npm install` and `npm test`.
  
  ## Shims
  
  ### Complete tests ###
  
  * Array.prototype.every
  * Array.prototype.filter
  * Array.prototype.forEach
  * Array.prototype.indexOf
  * Array.prototype.lastIndexOf
  * Array.prototype.map
  * Array.prototype.slice
  * Array.prototype.some
  * Array.prototype.sort
  * Array.prototype.reduce
  * Array.prototype.reduceRight
  * Array.prototype.push
  * Array.prototype.join
  * Array.isArray
  * Date.now
  * Date.prototype.toJSON
  * Function.prototype.bind
      * :warning: Caveat: the bound function has a prototype property.
      * :warning: Caveat: bound functions do not try too hard to keep you
        from manipulating their ``arguments`` and ``caller`` properties.
      * :warning: Caveat: bound functions don't have checks in ``call`` and
        ``apply`` to avoid executing as a constructor.
  * Number.prototype.toFixed
  * Number.prototype.toPrecision
  * Object.keys
  * String.prototype.split
  * String.prototype.trim
  * String.prototype.lastIndexOf
  * String.prototype.replace
      * Firefox (through v29) natively handles capturing groups incorrectly.
  * Date.parse (for ISO parsing)
  * Date.prototype.toISOString
  * parseInt
  * parseFloat
  * Error.prototype.toString
  * Error.prototype.name
  * Error.prototype.message
  * RegExp.prototype.toString
  
  ## Shams
  
  * :warning: Object.create
  
      For the case of simply "begetting" an object that inherits
      prototypically from another, this should work fine across legacy
      engines.
  
      :warning: The second argument is passed to Object.defineProperties
      which will probably fail either silently or with extreme prejudice.
  
  * :warning: Object.getPrototypeOf
  
      This will return "undefined" in some cases.  It uses `__proto__` if
      it's available.  Failing that, it uses constructor.prototype, which
      depends on the constructor property of the object's prototype having
      not been replaced.  If your object was created like this, it won't
      work:
  
          function Foo() {
          }
          Foo.prototype = {};
  
      Because the prototype reassignment destroys the constructor
      property.
  
      This will work for all objects that were created using
      `Object.create` implemented with this library.
  
  * :warning: Object.getOwnPropertyNames
  
      This method uses Object.keys, so it will not be accurate on legacy
      engines.
  
  * Object.isSealed
  
      Returns "false" in all legacy engines for all objects, which is
      conveniently guaranteed to be accurate.
  
  * Object.isFrozen
  
      Returns "false" in all legacy engines for all objects, which is
      conveniently guaranteed to be accurate.
  
  * Object.isExtensible
  
      Works like a charm, by trying very hard to extend the object then
      redacting the extension.
  
  ### May fail
  
  * :warning: Object.getOwnPropertyDescriptor
  
      The behavior of this shim does not conform to ES5.  It should
      probably not be used at this time, until its behavior has been
      reviewed and been confirmed to be useful in legacy engines.
  
  * :warning: Object.defineProperty
  
      In the worst of circumstances, IE 8 provides a version of this
      method that only works on DOM objects.  This sham will not be
      installed.  The given version of `defineProperty` will throw an
      exception if used on non-DOM objects.
  
      In slightly better circumstances, this method will silently fail to
      set "writable", "enumerable", and "configurable" properties.
  
      Providing a getter or setter with "get" or "set" on a descriptor
      will silently fail on engines that lack "__defineGetter__" and
      "__defineSetter__", which include all versions of IE.
  
      https://github.com/es-shims/es5-shim/issues#issue/5
  
  * :warning: Object.defineProperties
  
      This uses the Object.defineProperty shim.
  
  * Object.seal
  
      Silently fails on all legacy engines.  This should be
      fine unless you are depending on the safety and security
      provisions of this method, which you cannot possibly
      obtain in legacy engines.
  
  * Object.freeze
  
      Silently fails on all legacy engines.  This should be
      fine unless you are depending on the safety and security
      provisions of this method, which you cannot possibly
      obtain in legacy engines.
  
  * Object.preventExtensions
  
      Silently fails on all legacy engines.  This should be
      fine unless you are depending on the safety and security
      provisions of this method, which you cannot possibly
      obtain in legacy engines.
  
  ### Example of applying ES compatability shims in a browser project
  
  ```html
  <script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.7/es5-shim.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.7/es5-sham.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/json3/3.3.2/json3.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.34.2/es6-shim.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.34.2/es6-sham.min.js"></script>
  <script src="https://wzrd.in/standalone/es7-shim@latest"></script>
  <script src="other-libs.js"></script>
  ```
  [npm-url]: https://npmjs.org/package/es5-shim
  [npm-version-svg]: http://versionbadg.es/es-shims/es5-shim.svg
  [travis-svg]: https://travis-ci.org/es-shims/es5-shim.svg
  [travis-url]: https://travis-ci.org/es-shims/es5-shim
  [deps-svg]: https://david-dm.org/es-shims/es5-shim.svg
  [deps-url]: https://david-dm.org/es-shims/es5-shim
  [dev-deps-svg]: https://david-dm.org/es-shims/es5-shim/dev-status.svg
  [dev-deps-url]: https://david-dm.org/es-shims/es5-shim#info=devDependencies
  [npm-badge-png]: https://nodei.co/npm/es5-shim.png?downloads=true&stars=true