What are the properties of ‘object’, the simplest and most basic class?
Answer
In Python, the object from which all classes inherit their most basic properties is called object. This allows us to customize everything about our new class, including how to initialize it, how to set descriptors, accepting arguments, and more.
For an in-depth view, take a look at the top answer of this StackOverflow post about the object we inherit from!
Why wasn’t this the first ever excercise for the class module? I felt this exercise has a better explanation of what objects are and throws off any confusion the first exercise brings when it asks to create a class to understand its syntax
In terms of pre-2015, JS did not have classes, proper, but the language implied a class structure. In truth, it’s only a way to conceptualize what it really is… A prototypal language.
All objects inherit from Object.prototype, meaning all those methods and other properties are accessible in the context of any object instance, be it a boolean, string, number, array, plain object or custom object, or function.
The closest thing to an ES class, is a JS constructor. The difference is that any function can be a constructor, but a class requires an explicit class definition.
Earlier in this course, we were told that “Whilst … not a strict ‘requirement’ it is a widely adopted convention” to capitalise the first letter of a class. But the object class always has a lower case “o” in the tutorials. Why is that?
Python 2 has reached its end of life and should be laid to rest. That said, if we look at the builtins we see they are all lower case…
str
int
float
bool
list
dict
etc. As for, class Dog(object):, in Python 3 we no longer have to specify object as the class our custom class will inherit from. It inherits by default, now.
class Dog:
In writing our own class definitions we should still maintain the convention of capitalizing their name. It is helpful in identifying instances.