JS custom methods & JS this Flashcards

1
Q

What is a method?

A

Function that is assigned to the property of an object

Has two types: instance(built-in) and static (called directly on an object)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How can you tell the difference between a method definition and a method call?

A

Method definition: it’s attached to an object

Method call has codes ready to execute when user calls upon it: object.method(arguments inputed)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Describe method definition syntax (structure)

A

Var keyword object name {
Property: function (
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Describe method call syntax (structure).

A

var keyword object(value)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How is a method different from any other function?

A

The difference is that a method is associated with an object, while a function is not.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the defining characteristic of Object-Oriented Programming?

A

Data(properties) paired with methods
Methods are behaviors
OOP puts it into shared place

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the four “principles” of Object-Oriented Programming?

A

abstraction - concept of abstraction has itself become a declarative statement –
Encapsulation -
Inheritance
Polymorphism

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is “abstraction”?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does API stand for?

A

application programming interface (API) is a connection between computers or between computer programs.

Like the DOM

Abstraction being used to

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the purpose of an API?

A

It is a type of software interface, offering a service to other pieces of software.

it allows programs interact together

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is this in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does it mean to say that this is an “implicit parameter”?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

When is the value of this determined in a function; call time or definition time?

A

call-time

just like explicit parameters, the value of this is determined when the function is called, not when it is defined.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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);
  }
};
A

it’s nothing

‘this’ doesn’t exist yet.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Given the above character object, what is the result of the following code snippet? Why?

A

It’s-a-me, Mario!

Because this is refers to the object it belongs to

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
Given the above character object, what is the result of the following code snippet? Why?
var hello = character.greet;
hello();
A

It’s-a-me, undefined!

Because
window doesn’t have a property named firstName or lastName

17
Q

How can you tell what the value of this will be for a particular function or method definition?

A

you can’t know

18
Q

How can you tell what the value of this is for a particular function or method call?

A

if there is a dot AND on the left,

  • there is an object.
  • left of the dot will be THIS