我试图在检查出昨天的css之后与CoffeeScript达成协议,我对此印象非常深刻。如何在CoffeeScript中编写此代码?
我比raw Javascript更像是一个jQuery wiz,所以我觉得它有点令人困惑,但同时我觉得考虑一下CoffeeScript是好的,因为它可以帮助我通过分析输出来获得更好的理解。
var Raw = (function($) {
$(function() {
Raw.initialize();
});
return {
_current: '',
initialize: function() {
this.initGlobal();
if(this.is('index')) {
this.initIndex();
}
else if(this.is('single')) {
this.initSingle();
}
},
initGlobal: function() {
atom_twitter();
atom_loading();
ratings();
},
initIndex: function() {
atom_scroll();
},
initSingle: function() {
atom_download();
},
is: function(page) {
if(this._current == '') {
this._current = $('body').attr('id');
}
return this._current == page;
}
};
})(jQuery);
任何想法从哪里开始?
到目前为止,我有这样的:
Raw = (($) ->
console.log 'hello world'
)(jQuery);
,输出:
(function() {
var raw;
raw = (function($) {
return console.log('hello world');
})(jQuery);
}).call(this);
嘛js2cofee转换器,我不认为代码将被_identical_,但功能不过,这绝对可以实现。 – omninonsense 2011-12-23 20:16:05
我建议将此问题迁移到[Code Review](http://codereview.stackexchange.com/)。 – 2011-12-23 20:20:01
@TrevorBurnham是某种类型的管理员能够做到这一点? – daryl 2011-12-23 20:53:07