Conteúdo do Curso
Object-Oriented Programming in JavaScript
Object-Oriented Programming in JavaScript
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.
Tarefa
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.
Tarefa
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.
Tudo estava claro?
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.
Tarefa
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.
Tarefa
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.
Tudo estava claro?
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.
Tarefa
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.
Tarefa
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.
Tudo estava claro?
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.
Tarefa
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.