このティースプーン一杯のコーヒー...
_pickInConf = (sourceConf,propsToPick...) ->
newConfWithPickedProperties = {}
newConfWithPickedProperties[key] = sourceConf[key] for key in Array::.concat.apply Array::,propsToPick when key in sourceConf
newConfWithPickedProperties
... にコンパイルされます:
_pickInConf = function() {
var key, newConfWithPickedProperties, propsToPick, sourceConf, _i, _len, _ref;
sourceConf = arguments[0], propsToPick = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
newConfWithPickedProperties = {};
_ref = Array.prototype.concat.apply(Array.prototype, propsToPick);
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
key = _ref[_i];
if (__indexOf.call(sourceConf, key) >= 0) {
newConfWithPickedProperties[key] = sourceConf[key];
}
}
return newConfWithPickedProperties;
};
...そして以下を利用します:
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
私はCoffeescriptコンパイラがこのチャンクをトランスコンパイルすることを期待していました:
when key in sourceConf
の中へ :
if (key in sourceConf) {
...私がJSでコーディングするつもりだったのは...
この種の JS を強制的に Coffescript に出力させる方法はありますか? または、 sourceConf が配列ではなくオブジェクトであることを理解させるには?
ご回答ありがとうございます。