OOP Flashcards

1
Q

What is a method?

A

a function which is a property of 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: declaring/defining. code is there but nothing happens

method call: DOT NOTATION
call the function to run the code

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

Describe method definition syntax (structure).

A
var objectName = {
methodName: function(parameters) {
code
return result
};
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Describe method call syntax (structure).

A

ObjectName.methodName(parameters);

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

it is the property of an object

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

IMPORTANT!

What is the defining characteristic of Object-Oriented Programming?

A

objects can contain both data (as properties) and behavior (as methods)

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
Encapsulation
Inheritance
Polymorphism

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

What is “abstraction”?

A

being able to work with (possibly) complex things in simple ways.

ex/ light switch

ex/ car automatic transmission

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

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

NUTSHELL: allows apps to disseminate or receive information between each other. interacting with an application to get or send info.

SIMPLE DEFINITION: an API delivers a user response to a system and sends the system’s response back to a user.

COMPLEX DEFITION: it is a set of functions that allows applications to access data and interact with external software components, operating systems, or microservices.

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

What is “this” in JavaScript?

A

reference to the lexical scope of the function at call time

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

“this” parameter does not need to be explicitly defined

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

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

character

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

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

A

you can’t know for sure until it is called

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

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

A

look left of the dot

that is typically the calling object

17
Q

What kind of inheritance does the JavaScript programming language use?

A

prototype-based (or prototypal) inheritance.

JavaScript objects give certain behaviors (methods) or data (properties) to other objects.

18
Q

What is a prototype in JavaScript?

A

an object with functionality that will be inherited down to any object connected to that prototype

original model on which something is patterned

19
Q

How is it possible to call methods on strings, arrays, and numbers even though those methods don’t actually exist on objects, arrays, and numbers?

A

You can set prototypes

20
Q

If an object does not have it’s own property or method by a given key, where does JavaScript look for it?

A

[[prototype]] chain

21
Q

IMPORTANT

What does the “new” operator do?

A

create an instance of a user-defined object type or of one of the built-in object types that has a constructor function.

  1. creates blank object
  2. adds property/fxns to new object __proto__to link to fxn’s prototype object
  3. binds newly created object to “this” (“this” now referes to object created in step 1)
  4. returns “this” if fxn doesnt return an object. no need to put in “return” keyword
22
Q

What property of JavaScript functions can store shared behavior for instances created with new?

A

.prototype property

23
Q

What does the instanceof operator do?

A

SIMPLE: checks to see if variable was created from a specific constructor

COMPLEX: tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object.

returns boolean

24
Q

Besides adding an event listener callback function to an element or the document, what is one way to delay the execution of a JavaScript function until some point in the future?

A

set timeout

25
Q

How can you set up a function to be called repeatedly without using a loop?

A

set interval

26
Q

What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?

A

1 second

27
Q

What do setTimeout() and setInterval() return?

A

setTimeout - returns positive integer

Interval - numeric nonzero value that identifies the timer

28
Q

What is AJAX?

A

Asynchronous JavaScript And XML

AJAX is a tool for making network requests within website without needing to load a new webpage

uses XML to request data and JS to display user data

29
Q

Which object is built into the browser for making HTTP requests in JavaScript?

A

xhr

XMLHttpRequest

30
Q

What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?

A

‘load’ event

WE CARE ABOUT ‘load’ & ‘error’

other events fired by xhr objects 
('progress' - update progress 
'load' - transfer complete
'error - transfer failed' 
'abort' - if client canceled)
31
Q

An XMLHttpRequest object has an addEventListener() method just like DOM elements.

How is it possible that they both share this functionality?

A

prototype chain:

event target (least specific) < event target xhr < xhr (most specific)

event target < node < DOM element