DoneJS StealJS jQuery ++ FuncUnit DocumentJS
3.0.0
2.3.27

 

  • Github
  • Twitter
  • Chat
  • Forum
  • Guides
  • Core
  • Ecosystem
  • Infrastructure
  • Legacy
    • can-ejs
    • can-list
    • can-map
      • prototype
        • DEFAULT-ATTR
        • attr
        • bind
        • compute
        • each
        • removeAttr
        • serialize
        • unbind
      • static
        • keys
    • can-map-backup
    • can-map-define
    • can-view-href
  • Bitovi
    • Bitovi.com
    • Blog
    • Consulting
    • Training
    • Open Source
  • Chat
  • Forum
  • Star
  • Follow @canjs
  • CanJS
  • /
  • Legacy
  • /
  • can-map
  • /
  • compute
  • / On this page
    • compute

      function

      Make a can.compute from an observable property.

      • source

      map.compute(attrName)

      Parameters

      1. attrName {String}:

        the property to bind to

      Returns

      {can-compute}:

      a can-compute bound to attrName

      compute is a convenience method for making computes from properties of Observes. More information about computes can be found under [can.compute].

      var map = new Map({a: 'Alexis'});
      var name = map.compute('a');
      name.bind('change', function(ev, nevVal, oldVal) {
          console.log('a changed from ' + oldVal + 'to' + newName + '.');
      });
      
      name(); // 'Alexis'
      
      map.attr('a', 'Adam'); // 'a changed from Alexis to Adam.'
      name(); // 'Adam'
      
      name('Alice'); // 'a changed from Adam to Alice.'
      name(); // 'Alice'
      

      CanJS is part of DoneJS. Created and maintained by the core DoneJS team and Bitovi. Currently 3.0.0.