Object Orienting Programming Basics :: part 2 :: properties vs methods
What is a property?
In the first part of the series, we have introduced the property color for our Animal class. Property is a named attribute. Instantiated object can get any value for the defined property.
We can assign any value to the property.
b = new Animal();
b.color = 'red';
b.color = 'pink';
b.color = 'blue';
We can assign the same value to different objects.
a = new Animal();
a.color = 'red';
c = new Animal();
c.color = 'red';
What is a method?
A method is an action that can be performed on object. Let's suppose that the programmer supplies the method move() to class Animal.
move() {
console.log(`I'm moving.`);
}
This is a simple method that show the message "I'm moving." in the console log every type it's called, whatever the object is.