Edit this page

up.util up.util.copy.key
JavaScript property

This feature is experimental. It may be changed or removed in a future version.

This property contains the name of a method that user-defined classes may implement to hook into the up.util.copy() protocol.

Example

We have a user-defined Account class that we want to use with up.util.copy():

class Account {
  constructor(email) {
    this.email = email
  }

  [up.util.copy.key]() {
    return new Account(this.email)
  }
}

Note

The protocol method is not actually named 'up.util.copy.key'. Instead it is named after the value of the up.util.copy.key property. To do so, the code sample above is using a computed property name in square brackets.

We may now use Account instances with up.util.copy():

original = new User('foo[@foo](https://github.com/foo){: .is_secondary}.com')

copy = up.util.copy(original)
console.log(copy.email) // prints 'foo[@foo](https://github.com/foo){: .is_secondary}.com'

original.email = 'bar[@bar](https://github.com/bar){: .is_secondary}.com' // change the original
console.log(copy.email) // still prints 'foo[@foo](https://github.com/foo){: .is_secondary}.com'

Value

key string
This website uses cookies to improve usability and analyze traffic.
I accept or learn more