cloneProtected method

void cloneProtected(
  1. GraphObject copy
)

Copies properties from this object to the given object, which must be of the same class. This is called by #copy. This method may be overridden.

For every property that you add to a subclass of a GraphObject-inheriting class, in this method you should assign its value to the copied object. For performance reasons you should set all of the same properties to this that the constructor does, and in the same order.

For example, let us define a custom Link class and add two properties:

function CustomLink() {
  go.Link.call(this);
  this._someNewProperty = 17;
  this._someNewProperty2 = [];  // an Array
}
go.Diagram.inherit(CustomLink, go.Link);

CustomLink.prototype.cloneProtected = function() {
  // Always call the base method in an override
  // In TypeScript you would use: super.cloneProtected(copy);
  go.Link.prototype.cloneProtected.call(this, copy);
  // assign every new property to the copy:
  copy._someNewProperty = this._someNewProperty;
  copy._someNewProperty2 = this._someNewProperty2.slice(0);  // make a copy of the Array
}

This ensures that copies of GraphObjects and their subclasses are faithful reproductions. Consider for properties that are references to objects whether the reference should be shared or whether that object value should be copied as well, resulting in a less shallow copy. This is demonstrated above by making a copy of the property value that is an Array, so that modifications to the Array will not be shared by copies of the CustomLink. Further copies of the Array items might be warranted, depending on their purpose.

Please read the Introduction page on Extensions for how to override methods and how to call this base method.

Implementation

void cloneProtected(_i3.GraphObject copy) {
  _i4.callMethod(
    this,
    'cloneProtected',
    [copy],
  );
}