如何将这个 javascript 转换为 Coffeescript?
$(function() {
function AppViewModel() {
this.firstName = ko.observable();
}
ko.applyBindings(new AppViewModel());
});
我尝试过这个,但它破坏了 knockoutjs 绑定(bind)
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);
最佳答案
这成功了。但我认为真正的解决方案是——学习knockoutjs时不要使用coffeescript
jQuery ->
class AppViewModel
firstName : ko.observable()
ko.applyBindings(new AppViewModel)
关于javascript - knockoutjs javascript 到 CoffeeScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11119711/