Methods
A method is a function or codeblock assigned to a property. The method is then called through the object via the dot and call operators. Continuing the example above:
obj.perimeter = {|| this.sides * this.length}
? obj.perimeter( ) // Displays 12
As you may have deduced by now, the object referred to by the variable obj represents a regular polygon. The perimeter of such a polygon is the product of the length of each side and the number of sides.
The reference this is used to access these values. In the method of an object, the reference this always refers to the object that called the method. By using this, you can write code that can be shared by different objects, and even different classes, as long as the property names are the same.