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

can.compute in a can.List

$
0
0
Just wondering why this doesn't work. This actually came up in our CanJS Boston meetup last night:
  1. Numbers = can.List.extend({
        sum: can.compute(function() {
            var sum = 0;
            this.each(function(val) {
                sum += val;
            });
            return sum;
        })
    })

    var nums = new Numbers([1,2,3]);
    nums.sum();

It fails with: Uncaught TypeError: Object [object global] has no method 'each'


"this" is equal to the global object when the compute is called.

Is something that you shouldn't be or need to do?


Viewing all articles
Browse latest Browse all 3491

Trending Articles