• function

compute.bind can.computed.bind


Bind an event handler to a compute.

compute.bind(eventType, handler)


  1. eventType {String}

    The event to bind this handler to. The only event type that computes emit is change.

  2. handler {function(Object, Object, Object)}

    The handler to call when the event happens. The handler should have three parameters:

    • event is the event object.
    • newVal is the newly-computed value of the compute.
    • oldVal is the value of the compute before it changed.

    bind lets you listen to a compute to know when it changes. It works just like can.Observe's bind:

    var tally = can.compute(0);
    tally.bind('change', function(ev, newVal, oldVal) {
        console.log('The tally is now at ' + newVal + '.');
    tally(tally() + 5); // The log reads:
                        // 'The tally is now at 5.'