0220 js custom methods Flashcards
What is a method?
A method is a function which is a property of an object.
more: 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 can you tell the difference between a method definition and a method call?
definition has the word function, but calling does not
definitions have parameters, but calling has arguments
Describe (or write or type out) method definition syntax (structure).
here is an object:
var doggo = {
bork: function () {
return ‘bork! bork! bork!’;
},
lick: function () {
return ‘mlem’;
}
};
the function is this part:
bork: function () {
return ‘bork! bork! bork!’;
},
the property is listed as per usual, with a colon, with no parameters.
next, the word “function” is written, with brackets
next any parameters are typed into the brackets, separated by commas
next, opening curly brace
then the code block with possible return statement
next, closing curly brace
Describe method call syntax (structure).
e.g.
doggo.bork( );
type the object
then type the property
then type the brackets with any necessary arguments
How is a method different from any other function?
it is a property of an object as opposed to a standalone function
it can only be used as part of an object
What is the defining characteristic of Object-Oriented Programming?
What are the four “principles” of Object-Oriented Programming?
Abstraction
Encapsulation
Inheritance
Polymorphism
What is “abstraction”?
a simple way of being able to work with (possibly) complex things
e.g. i click on a pic link but the computer is actually doing a gazillion things to render the pic.
i don’t have to do those things. i just need to click!
What does API stand for?
application programming interface (API)
extra:
it is a way for two or more computer programs to communicate with each other
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
what is an anonymous function
a function without a name