Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

When is it appropriate to use a method vs a compute within a can.Component scope?

$
0
0
I noticed in the canjs doc's linked to below that the can.Component examples frequently use functions in place of where can.Computes would suffice. Is there any advantage either way here? Within the view layer, wouldn't page be converted into a compute regardless, making it less efficient than had it been a compute within the prototype?

  1. var CustomMap = can.Map.extend({
  2. offset: 0,
  3. limit: 20,
  4. page: function(){
  5. return Math.floor(this.attr('offset') / this.attr('limit')) + 1;
  6. },
  7. computedPage: can.compute(function() {
  8.   return Math.floor(this.attr('offset') / this.attr('limit')) + 1;
  9. })
  10. })

Viewing all articles
Browse latest Browse all 3491

Trending Articles