How Marketing Changed OOP In JavaScript<\/h1>\nJuan Diego Rodr\u00edguez<\/address>\n 2023-12-04T14:00:00+00:00
\n 2024-06-12T20:05:40+00:00
\n <\/header>\n
Even though JavaScript\u2019s name was coined from the Java language, the two languages are worlds apart. JavaScript has more in common with Lisp<\/a> and Scheme<\/a>, sharing features such as first-class functions and lexical scoping.<\/p>\nJavaScript also borrows its prototypal inheritance from the Self<\/a> language. This inheritance mechanism is perhaps what many — if not most — developers do not spend enough time to understand, mainly because it isn\u2019t a requirement to start working with JavaScript. That characteristic can be seen as either a design flaw or a stroke of genius. That said, JavaScript\u2019s prototypal nature was marketed and hidden behind a \u201cJava for the web\u201d mask. We\u2019ll elaborate more on that as we go on.<\/p>\nJavaScript isn\u2019t confident in its own prototypal nature, so it gives developers the tools to approach the language without ever having to touch a prototype. This was an attempt to be easily understood by every developer, especially those coming from class-based languages, such as Java, and would later become one of JavaScript\u2019s biggest enemies for years to come: You don\u2019t have to understand how JavaScript works to code in JavaScript.<\/p>\n
What Is Classical Object-Oriented Programming?<\/h2>\n
Classical object-oriented programming (OOP)<\/strong> revolves around the concept of classes and instances and is widely used in languages like Java, C++, C#, and many others. A class is a blueprint or template for creating objects. It defines the structure and behavior of objects that belong to that class and encapsulates properties and methods. On the other hand, objects are instances of classes. When you create an object from a class, you\u2019re essentially creating a specific instance that inherits the structure and behavior defined in the class while also giving each object an individual state.<\/p>\nOOP has many fundamental concepts, but we will focus on inheritance<\/strong>, a mechanism that allows one class to take on the properties and methods of another class. This facilitates code reuse and the creation of a hierarchy of classes.<\/p>\n<\/p>\n <\/p>\n
<\/p>\n
<\/a>\n Diagram showing one class with two objects connected to another class connected to two more objects. (Large preview<\/a>)
\n <\/figcaption><\/figure>\n\n
\n 2024-06-12T20:05:40+00:00
\n <\/header>\n
JavaScript also borrows its prototypal inheritance from the Self<\/a> language. This inheritance mechanism is perhaps what many — if not most — developers do not spend enough time to understand, mainly because it isn\u2019t a requirement to start working with JavaScript. That characteristic can be seen as either a design flaw or a stroke of genius. That said, JavaScript\u2019s prototypal nature was marketed and hidden behind a \u201cJava for the web\u201d mask. We\u2019ll elaborate more on that as we go on.<\/p>\n JavaScript isn\u2019t confident in its own prototypal nature, so it gives developers the tools to approach the language without ever having to touch a prototype. This was an attempt to be easily understood by every developer, especially those coming from class-based languages, such as Java, and would later become one of JavaScript\u2019s biggest enemies for years to come: You don\u2019t have to understand how JavaScript works to code in JavaScript.<\/p>\n Classical object-oriented programming (OOP)<\/strong> revolves around the concept of classes and instances and is widely used in languages like Java, C++, C#, and many others. A class is a blueprint or template for creating objects. It defines the structure and behavior of objects that belong to that class and encapsulates properties and methods. On the other hand, objects are instances of classes. When you create an object from a class, you\u2019re essentially creating a specific instance that inherits the structure and behavior defined in the class while also giving each object an individual state.<\/p>\n OOP has many fundamental concepts, but we will focus on inheritance<\/strong>, a mechanism that allows one class to take on the properties and methods of another class. This facilitates code reuse and the creation of a hierarchy of classes.<\/p>\n <\/p>\n <\/a>What Is Classical Object-Oriented Programming?<\/h2>\n
<\/p>\n
\n <\/figcaption><\/figure>\n