Created
October 20, 2010 02:05
-
-
Save tristanz/635621 to your computer and use it in GitHub Desktop.
KnockoutJS in CoffeeScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I'm trying to make KnockoutJS's dependentObservables work in CoffeeScript. See | |
http://github.com/SteveSanderson/knockout/wiki/Observables | |
A typical example is: | |
var viewModel = { | |
firstName: ko.observable('Bob'), | |
lastName: ko.observable('Smith') | |
}; | |
viewModel.fullName = ko.dependentObservable(function() { | |
return this.firstName() + " " + this.lastName(); | |
}, viewModel); | |
It's unclear to me how to reproduce this in CoffeeScript. I'd like to write something like: | |
class ViewModel | |
firstName: ko.observable('Bob') | |
firstName: ko.observable('Smith') | |
fullName : ko.dependentObservable(=> | |
@firstName + " " + lastName | |
viewmodel = new ViewModel |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
class ViewModel
firstName: ko.observable 'Bob'
lastName: ko.obserable 'Smith'
fullName: ko.dependentObservable () ->
@firstname + " " + lastName
viewmodel = new ViewModel
That should work, keep in mind that i had to "space" things instead of tabbing