OOP Flashcards
What is a method?
JavaScript methods are actions that can be performed on objects.
How can you tell the difference between a method definition and a method call?
a method definition is what it will do or can do and how
a method call is it actually doing what its supposed to
Describe method definition syntax (structure).
name then colon followed by function and params the opening code block braces then code then closing code block braces
Describe method call syntax (structure).
the object name followed by the method and parenthesis and arguments if any
How is a method different from any other function?
methods are defined in an object while functions are not
What is the defining characteristic of Object-Oriented Programming?
A feature of objects is that an object’s own procedures can access and often modify the data fields of itself (objects have a notion of this or self)
/can contain both data and methods(functionality)
What are the four “principles” of Object-Oriented Programming?
- Encapsulation
- Abstraction
- Inheritance
- Polymorphism
What is this in JavaScript?
implicit parameter of all JS functions / gives you the lexical scope of whatever it is in
What does it mean to say that this is an “implicit parameter”?
that it is available in a function’s code block even though it was never included in the function’s parameter list or declared with var.
When is the value of this determined in a function; call time or definition time?
the value of this is determined when the function is called
What does this refer to in the following code snippet? var character = { firstName: 'Mario', greet: function () { var message = 'It\'s-a-me, ' + this.firstName + '!'; console.log(message); } };
character
Given the above character object, what is the result of the following code snippet? Why?
character.greet();
‘It’s a me Mario! / this refers to character
Given the above character object, what is the result of the following code snippet? Why? var hello = character.greet; hello();
‘It’s a me undefined! / this is referring to the window
as hello is whats calling it
How can you tell what the value of this will be for a particular function or method definition?
depends on how its called. If its attached to an object then its the object. If not you cant really tell
How can you tell what the value of this is for a particular function or method call
Depends if it is attached to an object