javascript-custom-methods 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

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

Describe method definition syntax (structure).

Describe method call syntax (structure).

How is a method different from any other function?

A

method definition = no parenthesis.

method call = prenenthesis and possibly passed in arguments.

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

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

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

Describe method definition syntax (structure).

A

similar to getter/setter syntax.

methods defined in object literals more consistent with methods in classes.

const obj =
{
foo: function () { … } ,
bar: function () { … } ,
};

const obj = {
foo() {
// …
},
bar() {
// …
},
};

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

Describe method call syntax (structure).

A

method syntax is not equivalent to a normal property with a function as its value
METHODS CANNOT BE CONSTRUCTORS

a property created as
a function can be used as
a constructor.

const obj = {
method() {},
};

new obj.method();
// TypeError:
obj.method is not a constructor

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

How is a method different from any other function?

A

Method definition is a
shorter syntax for defining
a function property in
an object initializer.

It can also be used in classes.

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

What is the defining characteristic of Object-Oriented Programming?

A

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

We can keep data and related functionality close together but also being able to separate them.

thsi way its easier to separate ideas and concepts for better structure and organization

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
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
9
Q

What is “abstraction”?

A

simplifying complex things into more simplier components. The process of removing or generalizing physical, spatial, or temporal details.

The Document Object Model is a software example of an abstraction.

Its not the original HTML text, but instead a tree of JavaScript objects with convenient methods and properties that allow you to manipulate the document as the user interacts with it.

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

What does API stand for?

A

application programming interface (API).

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

What is the purpose of an API?

A

the purpose of every software API is to give programmers a way to interact with a system in a simplified, consistent fashion: aka, an abstraction.

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