Object-Oriented Programming in JavaScript

Object-Oriented Programming in JavaScript

Objects, why are they important? Object-Oriented Programming in JavaScript

What is an Object?

Ruby programming language is often referred to as being the language where everything is an Object.

2.6.1 :001 > Class.ancestors

=> [Class, Module, Object, Kernel, BasicObject]

If you look at this code snippet taken from a terminal, we are calling .ancestors to trace the inheritance of Class . This reveals the parent tree to us and allows us to see that in fact, all Ruby is actually an Object that you can trace all the up to the BasicObject. Well, JavaScript is similar in that literally almost everything in JS is an Object. You can spend hours debating the pros and cons of this or discussing how when JS was created it was not expected to be as popular as it is today, so they made everything Objects.

> typeof{Function}

'object'

But I digress, JS is in fact all Objects, and well what in the world is an Object? Objects are ways to contain data and code that can be used to represent real-world things (objects) into our code. In Object-Oriented Programming (OOP), programmers ask themselves how can this object be best represented? What makes this object unique, how can you best recognize it?

For example, how would one represent a Dog in code? Do we have to think about what makes a dog a dog? What are the attributes associated with being a dog? We know a dog can have a name, it can speak by barking, it can wag its tail. To best represent this, we use Classes and constructors to add these attributes to a dog whenever a program creates it.

code-newbie javascript

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

4 Ways You Can Get Rid of Dirty Side Effects for Cleaner Code in JavaScript

4 Ways You Can Get Rid of Dirty Side Effects for Cleaner Code in JavaScript. Bugs are born in many ways. Creating side effects is one of them. Some people say side effects are evil, some say they’re not.

Static Code Analysis: What It Is? How to Use It?

Static code analysis is a method of debugging by examining source code before a program is run. It's done by analyzing a set of code against a set (or multiple sets) of coding rules. Static code analysis and static analysis are often used interchangeably, along with source code analysis.

Who Else Wants to Write Clean JavaScript Code?

Who Else Wants to Write Clean JavaScript Code? 7 Tips to Make Your Coworkers Fall in Love With Your Code.

Top 15 Simple Coding Techniques to Get Your Tasks Done with Shorter Code in JavaScript

Don’t waste time writing long code while you can make it short, yet clearer and easier to read. In this Javascript tutorial, we'll discuss 15 Simple Coding Techniques to Get Your Tasks Done with Shorter Code in JavaScript

The Code that Runs Your JavaScript Code

How often do you think about the environment that your code runs in, and the resources that are available to it when it runs? Understanding the ‘runtime’ environment can help us make better choices as JavaScript developers when writing code.