2021-10-17 18:26:00 +02:00
|
|
|
---
|
2022-09-29 18:08:09 +02:00
|
|
|
title: Snippet.clone()
|
2021-10-17 18:26:00 +02:00
|
|
|
---
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-09-29 18:08:09 +02:00
|
|
|
The `Snippet.clone()` method returns a new Snippets object that is a deep copy
|
|
|
|
of this one.
|
|
|
|
|
|
|
|
## Signature
|
|
|
|
|
2021-08-25 16:09:31 +02:00
|
|
|
```js
|
|
|
|
Snippet snippet.clone()
|
|
|
|
```
|
|
|
|
|
2022-09-29 18:08:09 +02:00
|
|
|
## Example
|
2022-01-19 11:31:39 +01:00
|
|
|
|
2022-09-29 18:08:09 +02:00
|
|
|
<Example caption="An example of the Snippet.clone() method">
|
2021-08-25 16:09:31 +02:00
|
|
|
```js
|
2022-09-29 18:08:09 +02:00
|
|
|
({ Point, Path, paths, Snippet, snippets, part }) => {
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-09-29 18:08:09 +02:00
|
|
|
snippets.demo = new Snippet("logo", new Point(0,0))
|
|
|
|
.attr("style", "color: #f006")
|
|
|
|
|
|
|
|
snippets.clone = snippets.demo
|
|
|
|
.clone()
|
|
|
|
.attr("data-scale", 0.5)
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-09-29 18:08:09 +02:00
|
|
|
// Prevent clipping
|
|
|
|
paths.diag = new Path()
|
|
|
|
.move(new Point(-25,-30))
|
|
|
|
.move(new Point(25,15))
|
|
|
|
|
|
|
|
return part
|
|
|
|
}
|
2021-08-25 16:09:31 +02:00
|
|
|
```
|
2022-09-29 18:08:09 +02:00
|
|
|
</Example>
|
|
|
|
|