Generator 的 this
function* hello(){
this.name = "world";
this.say = function(){
return this; // otherThis
}
return this; // oneThis
}
let gen = hello.call(hello.prototype); // 必须
let oneThis = gen.next().value;
let otherThis = gen.say();
oneThis === otherThis // false
otherThis === gen // true
oneThis === otherThis.__proto__ // true
oneThis === hello.prototype // true
otherThis instanceof hello // true
oneThis.name // world
otherThis.name // world
由上代码可以看出两个各方式返回的this并不是都代表hello函数的实例;其中oneThis指向hello函数的原型hello.prototype,otherThis指向hello的实例