can-define
Version:
Create observable objects with JS dot operator compatibility
42 lines (27 loc) • 1.08 kB
Markdown
`slice` creates a copy of a portion of the DefineList.
```js
import {DefineList} from "can";
const list = new DefineList(["Alice", "Bob", "Charlie", "Daniel", "Eve"]);
const newList = list.slice(1, 4);
console.log(newList.get()); //-> ["Bob", "Charlie", "Daniel"]
```
If _end_ is not supplied, `slice` will copy until the end of the list.
## Use
`slice` is the simplest way to copy a DefineList:
```js
import {DefineList} from "can";
const list = new DefineList(["Alice", "Bob", "Eve"]);
const copy = list.slice();
console.log(copy.get()); //-> ["Alice", "Bob", "Eve"]
console.log(list === copy); //-> false
```