Conteúdo do Curso
Object-Oriented Programming in JavaScript
Object-Oriented Programming in JavaScript
Constructor
Constructor is used for object creation and specifying some attributes. Look at this statement:
Student()
is a constructor of class Student
, so the student
variable is now a Student
object.
This simple constructor is using by default and creates an object only. But you can define a constructor that will initialize some object attributes.
student
object now has name Robert and age 22.
The syntax of the constructor inside the class is following:
By object creating, you can pass some arguments and use them inside constructor. But note that skipped parameters will have undefined
value. Look at the example and run it to see what happens.
Only name
and age
properties are defined in student
object because of 2 arguments while student
initialization.
Pass the arguments in order they are defined in constructor.
Tarefa
Extend existing constructor with arguments for university
and gpa
attributes. After that, change the line of object initialization by adding 2 more arguements inside Student()
statement.
Tarefa
Extend existing constructor with arguments for university
and gpa
attributes. After that, change the line of object initialization by adding 2 more arguements inside Student()
statement.
Tudo estava claro?
Constructor
Constructor is used for object creation and specifying some attributes. Look at this statement:
Student()
is a constructor of class Student
, so the student
variable is now a Student
object.
This simple constructor is using by default and creates an object only. But you can define a constructor that will initialize some object attributes.
student
object now has name Robert and age 22.
The syntax of the constructor inside the class is following:
By object creating, you can pass some arguments and use them inside constructor. But note that skipped parameters will have undefined
value. Look at the example and run it to see what happens.
Only name
and age
properties are defined in student
object because of 2 arguments while student
initialization.
Pass the arguments in order they are defined in constructor.
Tarefa
Extend existing constructor with arguments for university
and gpa
attributes. After that, change the line of object initialization by adding 2 more arguements inside Student()
statement.
Tarefa
Extend existing constructor with arguments for university
and gpa
attributes. After that, change the line of object initialization by adding 2 more arguements inside Student()
statement.
Tudo estava claro?
Constructor
Constructor is used for object creation and specifying some attributes. Look at this statement:
Student()
is a constructor of class Student
, so the student
variable is now a Student
object.
This simple constructor is using by default and creates an object only. But you can define a constructor that will initialize some object attributes.
student
object now has name Robert and age 22.
The syntax of the constructor inside the class is following:
By object creating, you can pass some arguments and use them inside constructor. But note that skipped parameters will have undefined
value. Look at the example and run it to see what happens.
Only name
and age
properties are defined in student
object because of 2 arguments while student
initialization.
Pass the arguments in order they are defined in constructor.
Tarefa
Extend existing constructor with arguments for university
and gpa
attributes. After that, change the line of object initialization by adding 2 more arguements inside Student()
statement.
Tarefa
Extend existing constructor with arguments for university
and gpa
attributes. After that, change the line of object initialization by adding 2 more arguements inside Student()
statement.
Tudo estava claro?
Constructor is used for object creation and specifying some attributes. Look at this statement:
Student()
is a constructor of class Student
, so the student
variable is now a Student
object.
This simple constructor is using by default and creates an object only. But you can define a constructor that will initialize some object attributes.
student
object now has name Robert and age 22.
The syntax of the constructor inside the class is following:
By object creating, you can pass some arguments and use them inside constructor. But note that skipped parameters will have undefined
value. Look at the example and run it to see what happens.
Only name
and age
properties are defined in student
object because of 2 arguments while student
initialization.
Pass the arguments in order they are defined in constructor.
Tarefa
Extend existing constructor with arguments for university
and gpa
attributes. After that, change the line of object initialization by adding 2 more arguements inside Student()
statement.