惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 司徒正美
Jina AI
Jina AI
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 三生石上(FineUI控件)
宝玉的分享
宝玉的分享
MyScale Blog
MyScale Blog
I
InfoQ
爱范儿
爱范儿
Microsoft Security Blog
Microsoft Security Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Stack Overflow Blog
Stack Overflow Blog
T
Tailwind CSS Blog
D
DataBreaches.Net
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
The Blog of Author Tim Ferriss
B
Blog
阮一峰的网络日志
阮一峰的网络日志
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
月光博客
月光博客
雷峰网
雷峰网
Recent Announcements
Recent Announcements
量子位
B
Blog RSS Feed

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Understanding Object-Oriented Programming in JavaScript
Anoop Rajori · 2026-04-27 · via DEV Community

OOPs is the programming style which organize code into Objects rather than lists of instructions. It helps developers to model complex systems by grouping related data and behaviours together.

Content List

What Object-Oriented Programming (OOP) means

A object oriented programming is a paradigm (a way of thinking) where you view progarm as collection of objects that interact with each other.

Instead of writing a script with lots of functions, you organize them as specific data (properties) and actions (methods) into a single unit called Object. It make you program to easy to reuse, organize, and scale as project get bigger.

Real-world analogy (blueprint → objects)

The easiest way to understand OOPs is to think about architect and house:

1. The Blueprint (class)

Architect design a detailed plan for a house, its not a house it self. It's just a detailed set of instructions of house which define overall structure of house like how walls constructs, how many window there are, where the doors go.

2. The House (object)

Using this plan builder can buid ten different houses, each house is a real physical thing made from that plan. While they all follow the same blueprint, one house might be printed blue or another is red.

What is a class in JavaScript

In javascript, class is used to create a blueprint before class was introduced in ES6 Prototypes are used. Prototypes were a bit more complex, class provides a cleaner, easy readable way to define how object should looks and behave.

In a class you define two things Properties & Methods:

  • Propeties: what the object is like color, name, size etc.
  • Methods: what the object does like run, stop, burk etc.

Creating objects using classes

To create a new object from a class we use new keyword. This process called instantiation,

class Laptop {
  // Class definition goes here
}

// Creating an object (instance) of the Laptop class
const myMacbook = new Laptop();
const myThinkpad = new Laptop();

Enter fullscreen mode Exit fullscreen mode

In this myMackbook and myThinkpad are the two distinct object created from same Laptop class.

Constructor method

The constructor is the special method which run authomatically the moment you create new object. It job is to set-up or initialize object's properties.

class Car {
  constructor(brand, color) {
    this.brand = brand; // 'this' refers to the object being created
    this.color = color;
  }
}

const myCar = new Car("Toyota", "Red");
console.log(myCar.brand); // Output: Toyota

Enter fullscreen mode Exit fullscreen mode

The this keyword is crucial, it tell javascript to assign a values to the unique object you are currently creating.

Methods inside a class

Methods are the function belongs to class, its used to perform tasks that object can do. Unlike standard function we don't use function keyword, we declare methods without it in class.

class Robot {
  constructor(name) {
    this.name = name;
  }

  // This is a method
  greet() {
    console.log(`Hello, my name is ${this.name}!`);
  }
}

const wallE = new Robot("WALL-E");
wallE.greet(); // Output: Hello, my name is WALL-E!

Enter fullscreen mode Exit fullscreen mode

Basic idea of encapsulation

The encapsulation is the practise of bundling data and mehods into a single unit (a class) and restricting access to some of the other objects components.

Think it like a capsul you dont need to see the chamical powder inside to take madicine, you just need to interact with outer shell.

In programming encapsulation: protect data from external code to accientally changing the internal variabals. Hide complexity: you only interact with simple method startEngine() wihtout needing to know complex logic happening inside.

In OOPs, its a good practise to use # or _ symbols before the any private variable to make it private, meaning it cannot be directly accessed or changed from outside the class.

Symmary

Object-Oriented Programming (OOP) organizes code into reusable objects containing data and behaviors. Classes act as blueprints, while objects are the physical instances. Constructors initialize properties, and methods define actions. Encapsulation protects internal data, hiding complexity and improving code structure, making systems easier to manage, scale, and maintain effectively over time.