DELAPARRA
Index
Color
NL
Category: Programming paradigms

Delegation

Explained by Updated

What is Delegation?

Delegation: When an object is asked for a property it doesn't have, it forwards ("delegates") the lookup to its prototype. Delegation, in prototype-based languages like JavaScript, means an object passes a property lookup on to another object when it does not have the property itself. If dog.speak does not exist on dog, JavaScript checks its prototype, then that prototype's prototype, and so on.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about Delegation

How is Delegation used in practice?

This prototype chain is how JavaScript implements inheritance under the hood. Classes in modern JavaScript are a friendlier syntax on top of it.

What should you keep in mind with Delegation?

Understanding it helps with debugging. A method that seems to exist on every object comes from Object.prototype. Changing a prototype affects every object that delegates to it, which is why changing built-in prototypes such as Array.prototype is considered bad practice. In other languages, delegation also means an object forwarding calls to a helper object it holds, which is a common alternative to inheritance.

At a glance

CategoryProgramming paradigms
Explained by
Updated

More Programming paradigms terms

All terms starting with D

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.