Created
January 16, 2013 13:09
-
-
Save sumskyi/4547031 to your computer and use it in GitHub Desktop.
knockout.js + CoffeeScript
learn.knockoutjs.com: Introduction
This file contains hidden or 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
<p>First name: <strong data-bind="text: firstName">Bert</strong></p> | |
<p>Last name: <strong data-bind="text: lastName">Bertington</strong></p> | |
<p>First name: <input data-bind="value: firstName" /></p> | |
<p>Last name: <input data-bind="value: lastName" /></p> | |
<p>Full name: <strong data-bind="text: fullName"></strong></p> | |
<button data-bind="click: capitalizeLastName">Go caps</button> |
This file contains hidden or 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
$ -> | |
AppViewModel = -> | |
@firstName = ko.observable("Bert") | |
@lastName = ko.observable("Bertington") | |
@fullName = ko.computed( | |
-> "#{@firstName()} #{@lastName()}" | |
@ | |
) | |
@capitalizeLastName = -> | |
currentVal = @lastName(); | |
@lastName currentVal.toUpperCase() | |
return | |
return | |
ko.applyBindings(new AppViewModel()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment