can
Version:
MIT-licensed, client-side, JavaScript framework that makes building rich web applications easy.
48 lines (40 loc) • 1.11 kB
Markdown
return a new List instance from the results.
`list.map( callback(item, index, listReference), context )`
{function(*, Number, can.List)} callback A function to call with each
element of the list.
{Object} context An optional object to use as `this` inside the callback.
{can.List} A new can.List instance.
```
var list = new can.List([1, 10, 100, 1000, 10000, 100000]);
var newList = list.map(function(element, index, listReference) {
var result;
switch(index) {
case 0: {
result = false;
break;
}
case 1: {
result = undefined;
break;
}
case 2: {
result = element;
break;
}
case 3: {
result = element * 5;
break;
}
default: {
result = listReference[index] /= 2;
break;
}
}
return result;
});
console.log(list); // [ 1, 10, 100, 1000, 5000, 50000]
console.log(newList); // [false, undefined, 100, 5000, 5000, 50000]
```
can.List.prototype.map map
can.List.prototype
Call a function on each element of a List and