「x」の結果、「y」の結果、「z」の結果は同じになると思います。
ライブスクリプトで:
x =
a: -> 3
b: -> 4
y = {}
for k, v of x
console.log "key: ", k, "val: ", v
y[k] = -> v.call this
console.log "y is: ", y
console.log "x's: ", x.a is x.b # should return false, returns false
console.log "y's: ", y.a is y.b # should return false, returns true
z = {}
z['a'] = ->
x.a.call this
z['b'] = ->
x.b.call this
console.log "z's: ", z.a is z.b # should return false, returns false
Javascript の場合:
var x, y, k, v, z;
x = {
a: function(){
return 3;
},
b: function(){
return 4;
}
};
y = {};
for (k in x) {
v = x[k];
console.log("key: ", k, "val: ", v);
y[k] = fn$;
}
console.log("y is: ", y);
console.log("x's: ", x.a === x.b);
console.log("y's: ", y.a === y.b);
z = {};
z['a'] = function(){
return x.a.call(this);
};
z['b'] = function(){
return x.b.call(this);
};
console.log("z's: ", z.a === z.b);
function fn$(){
return v.call(this);
}
版画:
x's: false # should be false, OK
y's: true # should be false, PROBLEM!
z's: false # should be false, OK