javascript-custom-methods Flashcards
What is a method?
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.
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?
method definition = no parenthesis.
method call = prenenthesis and possibly passed in arguments.
How can you tell the difference between a method definition and a method call?
Describe method definition syntax (structure).
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() {
// …
},
};
Describe method call syntax (structure).
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 is a method different from any other function?
Method definition is a
shorter syntax for defining
a function property in
an object initializer.
It can also be used in classes.
What is the defining characteristic of Object-Oriented Programming?
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
What are the four “principles” of Object-Oriented Programming?
Abstraction
Encapsulation
Inheritance
Polymorphism
What is “abstraction”?
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.
What does API stand for?
application programming interface (API).
What is the purpose of an API?
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.