JS custom methods & JS this Flashcards
What is a method?
Function that is assigned to the property of an object
Has two types: instance(built-in) and static (called directly on an object)
How can you tell the difference between a method definition and a method call?
Method definition: it’s attached to an object
Method call has codes ready to execute when user calls upon it: object.method(arguments inputed)
Describe method definition syntax (structure)
Var keyword object name {
Property: function (
}
Describe method call syntax (structure).
var keyword object(value)
How is a method different from any other function?
The difference is that a method is associated with an object, while a function is not.
What is the defining characteristic of Object-Oriented Programming?
Data(properties) paired with methods
Methods are behaviors
OOP puts it into shared place
What are the four “principles” of Object-Oriented Programming?
abstraction - concept of abstraction has itself become a declarative statement –
Encapsulation -
Inheritance
Polymorphism
What is “abstraction”?
process of removing physical, spatial, or temporal details or attributes in the study of objects or systems to focus attention on details of greater importance;
it is similar in nature to the process of generalization;
abstraction can also be referred to as modeling and is closely related to the concepts of theory and design
What does API stand for?
application programming interface (API) is a connection between computers or between computer programs.
Like the DOM
Abstraction being used to
What is the purpose of an API?
It is a type of software interface, offering a service to other pieces of software.
it allows programs interact together
What is this in JavaScript?
The JavaScript this keyword refers to the object it belongs to.
In a method, this refers to the owner object.
Alone, this refers to the global object (window)
In a function, this refers to the global object.
In a function, in strict mode, this is undefined.
In an event, this refers to the element that received the event.
Methods like call(), and apply() can refer this to any object.
What does it mean to say that this is an “implicit parameter”?
meaning 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?
call-time
just like explicit parameters, the value of this is determined when the function is called, not when it is defined.
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); } };
it’s nothing
‘this’ doesn’t exist yet.
Given the above character object, what is the result of the following code snippet? Why?
It’s-a-me, Mario!
Because this is refers to the object it belongs to