JS 2 Flashcards
What is a method?
a function which is a property of an object
How can you tell the difference between a method definition and a method call?
- a method definition has function definition and code block
- a method call is like a function call with object name dot and method name followed by parenthesis
Describe method definition syntax (structure).
- defined as a property with a value of a function in an object literal {methodName: function () {}}
- after the object’s creation, a function could be assigned to the method name’s property of the object objectName.methodName = function () {}
Describe method call syntax (structure).
object name, dot, method name, parenthesis
objectName.methodName()
How is a method different from any other function?
need dot or bracket notation to see what object the method in
What is the defining characteristic of Object-Oriented Programming?
- objects can contain both properties and methods
- data and behavior are combined
What are 4 principles of OOP?
Abstraction
Encapsulation
Inheritance
Polymorphism
What is “abstraction”?
- removing temporal details to focus on details of greater importance
- able to work with complex process in simple ways
What does API stand for?
application programming interface
What is the purpose of an API?
- allows users to use interface independently of implementation
- can use something without knowing how it was built
What is ‘this’ in JavaScript?
a property of an execution context that is a reference to its enclosing object
What does it mean to say that ‘this’ is an “implicit parameter”?
‘this’ is available in a function’s code block, even though it was never explicitly declared
When is the value of this determined in a function; call time or definition time?
call time
How can you tell what the value of this will be for a particular function or method definition?
you don’t know until it is called
How can you tell what the value of this is for a particular function or method call?
- if it is in a method inside an object, then it refers to that object
- if it is in a function inside the global scope, then it refers to Window