如何將此javascript轉換爲coffeescript?knockoutjs javascript into coffeescript
$(function() {
function AppViewModel() {
this.firstName = ko.observable();
}
ko.applyBindings(new AppViewModel());
});
我試過,但它打破了knockoutjs綁定
jQuery ->
AppViewModel = ->
this.firstName = ko.observable("something")
ko.applyBindings(new AppViewModel())
這裏就是CoffeeScript的生產
(function() {
jQuery(function() {
var ViewModel;
ViewModel = function() {
return this.firstName = ko.observable();
};
return ko.applyBindings(new ViewModel());
});
}).call(this);
gah,它是縮進錯誤。修正。 – Brand