Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Objects' Creating | Classes & Objects
Object-Oriented Programming in JavaScript
course content

Course Content

Object-Oriented Programming in JavaScript

Object-Oriented Programming in JavaScript

1. Classes & Objects
2. Encapsulation
3. Static
4. Inheritance

Objects' Creating

The object is an instance of some class. For example, for our class Rectangle, which describes some figures, we can create two figures:

There are two different objects, which are instances of Rectangle() class.

Now we’ll create two students:

These two objects have predefined methods and attributes. name, university, gpa, and age have undefined values.

To init or change the attribute’s value for an object, you can simply refer to it. Same you can do if you want to get the value of this attribute:

There is a simple way to detect which values object's attributes have: call console.log(object_name) and you'll see the JSON string that looks like:

There is a similar syntax to call the method:

Note that you can't create an instance of the class before the defintion of this class.

You can set some default name for attribute inside a class:

Now all objects will have undefined value of gpa and name, but predefined values of age and university.

You refer to methods and some single object attributes, so you’ll work with data in it.

Each object has a unique value of attributes, i. e. if you change the name for student1, the name of student2 doesn’t change.

Class notation is a formal and common representation of the behavior of different objects of this class.

Task

Set some default values for all Student class attributes. Then create object of class Student and output values of all the attributes for this object. In the end, call the sleep() method.

Task

Set some default values for all Student class attributes. Then create object of class Student and output values of all the attributes for this object. In the end, call the sleep() method.

Everything was clear?

Section 1. Chapter 4
toggle bottom row

Objects' Creating

The object is an instance of some class. For example, for our class Rectangle, which describes some figures, we can create two figures:

There are two different objects, which are instances of Rectangle() class.

Now we’ll create two students:

These two objects have predefined methods and attributes. name, university, gpa, and age have undefined values.

To init or change the attribute’s value for an object, you can simply refer to it. Same you can do if you want to get the value of this attribute:

There is a simple way to detect which values object's attributes have: call console.log(object_name) and you'll see the JSON string that looks like:

There is a similar syntax to call the method:

Note that you can't create an instance of the class before the defintion of this class.

You can set some default name for attribute inside a class:

Now all objects will have undefined value of gpa and name, but predefined values of age and university.

You refer to methods and some single object attributes, so you’ll work with data in it.

Each object has a unique value of attributes, i. e. if you change the name for student1, the name of student2 doesn’t change.

Class notation is a formal and common representation of the behavior of different objects of this class.

Task

Set some default values for all Student class attributes. Then create object of class Student and output values of all the attributes for this object. In the end, call the sleep() method.

Task

Set some default values for all Student class attributes. Then create object of class Student and output values of all the attributes for this object. In the end, call the sleep() method.

Everything was clear?

Section 1. Chapter 4
toggle bottom row

Objects' Creating

The object is an instance of some class. For example, for our class Rectangle, which describes some figures, we can create two figures:

There are two different objects, which are instances of Rectangle() class.

Now we’ll create two students:

These two objects have predefined methods and attributes. name, university, gpa, and age have undefined values.

To init or change the attribute’s value for an object, you can simply refer to it. Same you can do if you want to get the value of this attribute:

There is a simple way to detect which values object's attributes have: call console.log(object_name) and you'll see the JSON string that looks like:

There is a similar syntax to call the method:

Note that you can't create an instance of the class before the defintion of this class.

You can set some default name for attribute inside a class:

Now all objects will have undefined value of gpa and name, but predefined values of age and university.

You refer to methods and some single object attributes, so you’ll work with data in it.

Each object has a unique value of attributes, i. e. if you change the name for student1, the name of student2 doesn’t change.

Class notation is a formal and common representation of the behavior of different objects of this class.

Task

Set some default values for all Student class attributes. Then create object of class Student and output values of all the attributes for this object. In the end, call the sleep() method.

Task

Set some default values for all Student class attributes. Then create object of class Student and output values of all the attributes for this object. In the end, call the sleep() method.

Everything was clear?

The object is an instance of some class. For example, for our class Rectangle, which describes some figures, we can create two figures:

There are two different objects, which are instances of Rectangle() class.

Now we’ll create two students:

These two objects have predefined methods and attributes. name, university, gpa, and age have undefined values.

To init or change the attribute’s value for an object, you can simply refer to it. Same you can do if you want to get the value of this attribute:

There is a simple way to detect which values object's attributes have: call console.log(object_name) and you'll see the JSON string that looks like:

There is a similar syntax to call the method:

Note that you can't create an instance of the class before the defintion of this class.

You can set some default name for attribute inside a class:

Now all objects will have undefined value of gpa and name, but predefined values of age and university.

You refer to methods and some single object attributes, so you’ll work with data in it.

Each object has a unique value of attributes, i. e. if you change the name for student1, the name of student2 doesn’t change.

Class notation is a formal and common representation of the behavior of different objects of this class.

Task

Set some default values for all Student class attributes. Then create object of class Student and output values of all the attributes for this object. In the end, call the sleep() method.

Section 1. Chapter 4
Switch to desktop for real-world practiceContinue from where you are using one of the options below
We're sorry to hear that something went wrong. What happened?
some-alt