IT lexicon › Programming › Constructor

Constructor

Programming På svenska → Updated: 2026-05-24

A special function that runs when an object is created via new MyClass().

Initialises fields and optionally allocates resources. JS/TypeScript: constructor(). Python: __init__. Rust: convention is fn new(). Heavy constructors are considered bad design — make the object easy to create.

← Back to the lexicon