Objects Flashcards
What are objects?
- collection of variables and functions
- they represent the attributes and behaviour of something used in a program
What are variable tied to object called?
Properties
What are function tied to object called?
Methods
Properties and methods are also called?
Properties = attributes
Methods = behaviors
What is dot notation used for? (.currentTime)
It can be used to add a property or add a method and can also be used to consume
What is the literal notation to create an object?
E.g
let nameOfTheObject = {}
How do you add property to an object?
objectName.property = ‘something’
How do you add a method to an object?
objectName.functionName = function(){ //cool stuff }
How do you change the value of an object property?
Whit this syntax:
myObject.myProperty = newValue
How can a constructor be differentiate from a function?
The name in the function is capitalized
What is a constructor?
A constructor is a function that has as a purpose to create objects
Create an object ‘mouse’ and give it 3 property and 1 methods
let mouse = {}
mouse. brand = ‘logitech’
mouse. color = ‘black’
mouse. wireless = ‘true’
mouse.leftClick = function() {
consol.log(‘LEFT CLICKKKK’)
}
What does the key word ‘this’ indicate?
‘This’ is used in constructor to replace the name of the object
What is the syntax of a constructor?
function. NameOfConstructor (brand,model,color){
this. brand = …
this. model = …
this. color = …
this.something = function{
alert(…)
}
}
When a function name starts with a capital letter what does that mean?
It means it is a constructor