1 | /**
|
2 | * Copyright 2013-present, Facebook, Inc.
|
3 | * All rights reserved.
|
4 | *
|
5 | * This source code is licensed under the BSD-style license found in the
|
6 | * LICENSE file in the root directory of this source tree. An additional grant
|
7 | * of patent rights can be found in the PATENTS file in the same directory.
|
8 | *
|
9 | *
|
10 | */
|
11 |
|
12 | ;
|
13 |
|
14 | /* global Symbol */
|
15 |
|
16 | var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
|
17 | var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec.
|
18 |
|
19 | /**
|
20 | * Returns the iterator method function contained on the iterable object.
|
21 | *
|
22 | * Be sure to invoke the function with the iterable as context:
|
23 | *
|
24 | * var iteratorFn = getIteratorFn(myIterable);
|
25 | * if (iteratorFn) {
|
26 | * var iterator = iteratorFn.call(myIterable);
|
27 | * ...
|
28 | * }
|
29 | *
|
30 | * @param {?object} maybeIterable
|
31 | * @return {?function}
|
32 | */
|
33 | function getIteratorFn(maybeIterable) {
|
34 | var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]);
|
35 | if (typeof iteratorFn === 'function') {
|
36 | return iteratorFn;
|
37 | }
|
38 | }
|
39 |
|
40 | module.exports = getIteratorFn; |
\ | No newline at end of file |