본문 바로가기
728x90
반응형
SMALL

개념/혼자 공부하는 Javascript60

method) private ### Key Points of Each Class: - **Constructor**: Checks if the provided length is greater than 0. If it's not, an error is thrown, preventing the creation of a Square with a non-positive side length. - **`getPerimeter` Method**: Returns the perimeter of the square, calculated as four times the length of one side. - **`getArea` Method**: Returns the area of the square, calculated as the length of.. 2025. 1. 24.
class) Ractangle class ### Basic Rectangle Class - **`Rectangle` class**: Defines a rectangle with width and height properties, methods to calculate perimeter (`getPerimeter`) and area (`getArea`). - **`rectangle` instance**: Demonstrates creating a `Rectangle` object with a width of 10 and height of 20, then logs its perimeter and area. ### Square Classes Demonstrating Different Approaches 1. **`Square` class (Direct.. 2025. 1. 23.
method) forEach() - **Array of Numbers**: An array named `numbers` is defined, containing five numerical values: `[273, 23, 42, 152, 35]`. - **`forEach` Method**: This JavaScript method is called on the `numbers` array. The `forEach` method is used to execute a function for each element in the array. It's a part of JavaScript's `Array` prototype, making it available on all array instances. - **Callback Function**.. 2025. 1. 22.
method) getter and setter method ### Class Definition: `Square` - The `Square` class is designed to model a square with a specific length. - It uses a private field `#length` to store the square's side length. - The constructor takes an initial length for the square and sets it using the `setLength` method. - The `setLength` method updates the length of the square if the new length is greater than 0; otherwise, it throws an err.. 2025. 1. 21.
728x90
반응형
LIST