OOP Flashcards

1
Q

What is a method?

A

A method is a function which is a property of an object. There are two kinds of methods: instance methods which are built-in tasks performed by an object instance, or static methods which are tasks that are called directly on an object constructor.

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

defining - has a function code block

calling - has arguments

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

Describe method definition syntax (structure).

A

-property name:
-function definition(parameters)
code block

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

Describe method call syntax (structure).

A

object.method(arguments)

doggo.bork()

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.

if there is a dot - method
no dot - function

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

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

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

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

way for two or more computer programs to communicate with each other

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

What is this in JavaScript?

A

it’s an implicit parameter,

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

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

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

A

if only definition - can’t

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 is for a particular function or method call?

A

Find where the function is called and look for an object to the left of the dot

(if no dot, this = window)

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

What kind of inheritance does the JavaScript programming language use?

A

prototype based

prototypal

17
Q

What is a prototype in JavaScript?

A

source for shared behavior/data

sort of like a toolbox with all the tools

18
Q

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

A

within the prototype object

19
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

20
Q

What does the new operator do?

A
  1. makes a blank javascript object
  2. takes value of the prototype property and sets it
  3. turns new object into this (in the code block)
    4.
21
Q

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

A

.prototype

22
Q

What does the instanceof operator do?

A

The instanceof operator tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object. The return value is a boolean value.

we are created instances of ‘human’

23
Q

What is a “callback” function?

A

function you call inside another function

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

setTimeout()

25
Q

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

A

setInterval()

26
Q

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

A

If this parameter is omitted, a value of 0 is used, meaning execute “immediately”, or more accurately, the next event cycle.

27
Q

What do setTimeout() and setInterval() return?

A

timeoutID / intervalID