JavaScript Prototypes, Constructors, and Timers Flashcards
What is a “callback” function?
A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action
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?
setTimeout();
How can you set up a function to be called repeatedly without using a loop?
By using setInterval(); function
What is the default time delay if you omit the delay parameter from the setTimeout() or setIntervale()?
0 seconds, it is instant
What do setTimeout() and setInterval() return?
setTimeout() { [native code] }
setInterval() { [native code] }
A number data type that is used for an ID in IntervalID so you can stop the function from running
What kind of inheritance does the JavaScript programming language use?
Object.setPrototypeOf(object, prototype);
Prototype
What is the prototype in JavaScript?
A prototype is an object that will be inherited into another object
Prototypes are the mechanism by which JavaScript objects inherit features from one another.
How is it possible to call methods on strings, arrays, and numbers even though those methods don’t actually exist in objects, arrays, and numbers?
Strings, arrays, and numbers can borrow methods when they’re needed
JavaScript sets those prototypes on our behalf
If an object does not have it’s own property or method by a given key, where does JavaScript look for it?
It looks for it’s prototypal inheritance
What does a new operator do?
Allows you to create an instance of a user-defined object type or of one of the built-in object types that has a constructor function.
It creates a blank, plain JavaScript object
It adds a property to the new object (__proto__) that links to the constructor function’s prototype object
It binds the newly created object instance as the this context
Returns this if the function doesn’t return an object
What property of JavaScript functions can store shared behavior for instances created with new?
Function.prototype property
What does the instanceof operator do?
instanceof operator tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object