This is expected behavior because "this" doesn't mean anything in the first example.
But, you probably don't need to create "votes" as a compute. A normal function will be fine:
- votes : function() {
- return this.attr('upvotes') - this.attr('downvotes');
- };
Doing something like:
<%= commander.votes() %>
will already be live-bound. You don't need to declare functions as computes unless you plan to bind on them yourself.
If you do need to turn an instance's method into a compute, do:
var voteCompute = can.compute(commander.votes,commander);
voteCompute.bind("change",function(){})
BTW, it's not documented, but you can change any attribute into a compute like:
commander.compute("upvotes")
It could be useful to also allow:
commander.compute("votes")