property(obj, prop, [value])

Sets a property of an object or of any other given data item to the specified value. Alternatively an object of key value pairs can be used as the second argument to set several properties to specified values at once. To retrieve a list of available properties for the different data types, the inspect() method can be used.

Type: function

Parameter(s):

  • obj {Any}:

    An object or any other data item whose properties to change.

  • prop {String | Object}:

    A string describing an object’s property or alternatively an object containing key value pairs.

  • value {Any} Optional:

    A value of the appropriate type to set the object’s property to.

Returns:

  • {Any}:

    The object or other data item with the newly set property.

Example(s):

Sets name and fill color of an ellipse

var ell = ellipse(100, 100, 50, 50);
property(ell, "name", "Red Circle");
property(ell, "fillColor", color(255, 0, 0));

Sets name and fill color of a rectangle and locks it, using an object with key value pairs

var blueSquare = rect(100, 100, 50, 50);
var squareProps = {
  name: "Blue Square",
  fillColor: color(0, 0, 255),
  locked: true
}
property(blueSquare, squareProps);