๐ We jumped from procedural programming to object-oriented programming because things had started to become pointlessly lengthy:
๐คฎ A variable in line no.8 being accessed by a function on line no. 122 and the returned value of that function is used on line no. 55.
๐คฎ A variable in line no.8 being accessed by a function on line no. 122 and the returned value of that function is used on line no. 55.
๐ฅฒ This meant that coders had to scroll up & down a lot & keep track of a lot of stuff, which became useless in object-oriented programming because data and functions were clubbed together in entities called Objects.
But soon enough this approach became lengthy as well..๐
But soon enough this approach became lengthy as well..๐
๐งฟ When we needed to make a lot of objects of very similar kind (like users in a social media site), we had to use contructors & factory functions using the 'new' keyword.
โ๏ธ But in modern Javascript, we've an even more powerful concept of classes.
Let's look at them now....๐
โ๏ธ But in modern Javascript, we've an even more powerful concept of classes.
Let's look at them now....๐
๐ In object-oriented programming, a class is an extensible program-code-template for creating objects, providing initial values for state ( variables) & implementations of behavior ( functions or methods).
Let's break this ginormous sentence into easy-to-digest chunks..๐
Let's break this ginormous sentence into easy-to-digest chunks..๐
1๏ธโฃ ' a class is extensible ' -> meaning we can add features to the entity that a class will create
2๏ธโฃ 'program-code-template for creating objects,' -> meaning it is template for creating objects, i.e., the entity that a class creates is object.
2๏ธโฃ 'program-code-template for creating objects,' -> meaning it is template for creating objects, i.e., the entity that a class creates is object.
3๏ธโฃ 'providing initial values for state ( variables)' -> meaning that objects created using a class can or can not have variables that define the initial state of the class.
And finally....๐
And finally....๐
4๏ธโฃ '& implementations of behavior ( functions or methods)' -> meaning that the output-ed object can also have or not have functions that implement the behaviour.
๐ก Function of an object are called methods and if an object only has functions, it is said to have a behaviour.
๐ก Function of an object are called methods and if an object only has functions, it is said to have a behaviour.
I write threads daily on web dev so if you enjoyed this thread, please:
โ Follow me @sumitsaurabh927 for more of these.
โค๏ธ Each like, every comment of y'all motivates me to come up with awesome new stuff!
โ RT the tweet below to show me some love.
โ Follow me @sumitsaurabh927 for more of these.
โค๏ธ Each like, every comment of y'all motivates me to come up with awesome new stuff!
โ RT the tweet below to show me some love.
Loading suggestions...