File tree 1 file changed +16
-4
lines changed
1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -174,22 +174,34 @@ export const hyphenate = cached((str: string): string => {
174
174
} )
175
175
176
176
/**
177
- * Simple bind, faster than native
177
+ * Simple bind polyfill for environments that do not support it... e.g.
178
+ * PhantomJS 1.x. Technically we don't need this anymore since native bind is
179
+ * now more performant in most browsers, but removing it would be breaking for
180
+ * code that was able to run in PhantomJS 1.x, so this must be kept for
181
+ * backwards compatibility.
178
182
*/
179
- export function bind ( fn : Function , ctx : Object ) : Function {
183
+ function polyfillBind ( fn : Function , ctx : Object ) : Function {
180
184
function boundFn ( a ) {
181
- const l : number = arguments . length
185
+ const l = arguments . length
182
186
return l
183
187
? l > 1
184
188
? fn . apply ( ctx , arguments )
185
189
: fn . call ( ctx , a )
186
190
: fn . call ( ctx )
187
191
}
188
- // record original fn length
192
+
189
193
boundFn . _length = fn . length
190
194
return boundFn
191
195
}
192
196
197
+ function nativeBind ( fn : Function , ctx : Object ) : Function {
198
+ return fn . bind ( ctx )
199
+ }
200
+
201
+ export const bind = Function . prototype . bind
202
+ ? nativeBind
203
+ : polyfillBind
204
+
193
205
/**
194
206
* Convert an Array-like object to a real Array.
195
207
*/
You can’t perform that action at this time.
0 commit comments