JavaScript module 2 Flashcards
What is a method?
a property of an object that contains a function definition
How can you tell the difference between a method definition and a method call?
one is defined with a body and if it doesn’t have the body its a call
Describe method definition syntax (structure).
lick: function () {
return ‘mlem’;
}
Describe method call syntax (structure).
object.method()
How is a method different from any other function?
its pre defined
What is the defining characteristic of Object-Oriented Programming?
object’s own procedures can access and often modify the data fields of itself
What are the four “principles” of Object-Oriented Programming
Abstraction
Encapsulation
Inheritance
Polymorphism
What is “abstraction”?
a way of representing a complex process with a series of steps
What does API stand for?
Application programming interface
What is the purpose of an API?
a way for programs to communicate with each other
What is this in JavaScript?
a JavaScript keywords that references the current object. It has different values depending on where it is used: In a method, this refers to the owner object. Alone, this refers to the global object. In a function, this refers to the global object.
When is the value of this determined in a function; call time or definition time?
call time
1.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); } };
- Given the above character object, what is the result of the following code snippet? Why?
character. greet();
3.Given the above character object, what is the result of the following code snippet? Why? var hello = character.greet; hello();
- the character object.
- its a me mario!
- it’s a me undefined!, because its a stand alone function so “this” would be refering to the window
How can you tell what the value of this will be for a particular function or method definition?
you can guess if its used as you intended for it to be used
How can you tell what the value of this is for a particular function or method call?
for a function its a window
for a method if its a property of an object than its the object if its a nothing then its the window
What kind of inheritance does the JavaScript programming language use?
prototype based inheritance
What kind of inheritance does the JavaScript programming language use?
prototype-based (or prototypal) inheritance.
What is a prototype in JavaScript?
where JavaScript looks for a property if the object itself doesn’t have it
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?
they are all represented by objects
If an object does not have it’s own property or method by a given key, where does JavaScript look for it?
it looks at the prototype of the current object
What does the new operator do?
lets developers create an instance of a user-defined object type or of one of the built-in object types that has a constructor function
What property of JavaScript functions can store shared behavior for instances created with new?
prototype property
What does the instanceof operator do?
used to test if an object is of a given type(a descendant of). The result of the operation is either true or false
What does it mean to say that this is an “implicit parameter”?
that it changes meaning depending where its called
what is a callback function
a function that is passed in another function as an argument
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?
using the setTimeout() method
How can you set up a function to be called repeatedly without using a loop?
setInterval() method
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval() and deos that mean it executes immediately?
0
and no set timeout will be the last thing to run if you have other code, for example a function that has to run 1000x, that will run first and then after its done the setTimeout() method will run. it pretty much deprioroitizes whatever is in setTimeout() at 0
What do setTimeout() and setInterval() return?
it returns an interval ID
of the data type number