DEV Community

Cover image for "this" Keyword in OOP
Deep Patel
Deep Patel

Posted on

2 2 2 2 2

"this" Keyword in OOP

This is a submission for DEV Computer Science Challenge v24.06.12: One Byte Explainer.

Explainer

In a bakery, each baker has their own recipe book. When a baker says "this recipe," they mean a recipe from their own book. Similarly, in programming, this refers to the current object's properties and methods, like a baker's personal recipes.

Additional Context

In simple terms, think of this as a way for an object to say "me" or "myself" to refer to its own data and functions.

  • The this keyword in object-oriented programming refers to current instance of class.

  • In a method, using this can help distinguish between class attributes and parameters with the same name.

  • It can also be used to pass the current object as a parameter to other methods or constructors.

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay