Lecture JS - Objects - Part 2
Lecture JS - Objects - Part 2
JavaScript
In JavaScript, object-oriented programming (OOP) is a programming paradigm that is based on
the concept of objects. These objects can contain properties (which are key-value pairs) and
methods (functions that belong to the object). JavaScript allows you to work with objects and
create classes (templates for objects) using both older and newer techniques.
Basic Objects in JavaScript
IN JAVASCRIPT, OBJECTS ARE SIMPLY COLLECTIONS OF
PROPERTIES AND METHODS. HERE’S A BASIC EXAMPLE:
// Defining an object
const car = {
make: "Toyota",
model: "Corolla",
year: 2021,
displayInfo: function() {
console.log(`${this.year} ${this.make} ${this.model}`);
}
};
// Method
displayInfo() {
console.log(`${this.year} ${this.make} ${this.model}`);
}
}
// String representation
toString() {
const sign = this.imag >= 0 ? '+' : '-';
return `${this.real} ${sign} ${Math.abs(this.imag)}i`;
}
}
// Example usage:
Complex.prototype.conj = function() {
};
// Usage