Reputation: 1397
I am trying to sum all of the time submitted. But I don't think extjs allows the use of =+. Is there any other way I can achieve my goal?
This is what I am trying to show : console.log(time=+ time);
Upvotes: 0
Views: 43
Reputation: 62015
ExtJS is "just" JavaScript and there is no magical mapping from =+
to "sum all of" in JavaScript. Using the presented form is equivalent to time = (0 + time)
(the result of the expression is 0 + time
), which is hardly useful.
Either create a loop over the "times" (it should be a sequence such as an Array!) and use a "sum" variable; or, better, use one of the JavaScript functions/libraries (including those which are available in ExtJS) that support a sum
or higher-order fold/reduce
function1.
(In fact, Ext.Array already has a sum
.. how nice is that?)
1 The example on the MDC page for Array.reduce
is a summation function, presented here with some modifications for clarity:
var times = [0,1,2,3,4];
var sum = times.reduce(function(runningSum, number){
return runningSum + number;
}, 0);
If the items of the times
sequence are not numbers, then this can be used (with the appropriately modified function) as Ext.Array.sum
requires a sequence of numbers.
If older browsers must be targeted (such as IE 8 or before), use es5-shim.js and move on to more productive things.
Upvotes: 1