Skip to content

Instantly share code, notes, and snippets.

@tristanz
Created October 20, 2010 02:05
Show Gist options
  • Save tristanz/635621 to your computer and use it in GitHub Desktop.
Save tristanz/635621 to your computer and use it in GitHub Desktop.
KnockoutJS in CoffeeScript
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
@josebalius
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment