-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
36 lines (27 loc) · 829 Bytes
/
test.js
File metadata and controls
36 lines (27 loc) · 829 Bytes
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
/* jshint node:true, esnext:true */
'use strict';
let assert = require('assert');
let bind = require('./index').polyfill();
require('./index').polyfill();
function Counter(max) { this.max = max || 5; }
Counter.prototype.increment = function* increment() {
let current = 0;
while (current <= this.max) {
yield current++;
}
};
let c = new Counter();
let bound = bind(c, c.increment);
let polyfilled = c.increment.bind(c);
assert(c.increment.constructor.name === 'GeneratorFunction');
assert(bound.constructor.name === 'GeneratorFunction');
assert(polyfilled.constructor.name === 'GeneratorFunction');
let i = 0, j = c.max;
for (let cnt of c.increment()) { i = cnt; }
assert(i === j);
i = 0;
for (let cnt of bound()) { i = cnt; }
assert(i === j);
i = 0;
for (let cnt of polyfilled()) { i = cnt; }
assert(i === j);