我試圖在檢查出昨天的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