function* helloWorldGenerator() {
console.log('开始');
yield 'hello';
console.log('执行','hello');
yield 'world';
console.log('执行','world');
return 'ending';
}
var hw = helloWorldGenerator();
console.log(hw.next())
console.log(hw.next())
console.log(hw.next())
console.log(hw.next())
console.log(hw.next())
console.log(hw.next())
console.log(hw.next().done == true)
function *foo() {
yield 1;
yield 2;
yield 3;
yield 4;
yield 5;
return 6;
}
for (let v of foo()) {
console.log(v);
}
function* gen(x){
var y = yield x + 2;
return y;
}
var g = gen(1);
console.log(g.next()) // { value: 3, done: false }
console.log(g.next()) // { value: undefined, done: true }
function Point(x, y) {
this.x = x;
this.y = y;
}(9,8)
Point.prototype.toString = function () {
return '(' + this.x + ', ' + this.y + ')';
};
Point.toString2 = function () {
return '(' + this.x + '/' + this.y + ')';
};
var p = new Point(1, 2);
console.log(p.toString())
var p1 = new Point(3, 4);
console.log(Point.toString2())
console.log(Point.x)
console