• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/16

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

16 Cards in this Set

  • Front
  • Back
what are functions super powers?
Each object has a “super power” that distinguishes it from the rest; for functions it’s the ability to be invoked
How are functions created?
Functions are created via literals, for which a name is optional
What happens to extra arguments in a parameter list
Extra arguments are simply not bound to parameter names
What happens each function invocation in terms of what is passed on the parameters?
Each function invocation is passed two implicit parameters:
– arguments, a collection of the actual passed arguments
– this, a reference to the object serving as the function context
What are the different ways functions can be invoked and context of each way?
Functions can be invoked in various ways, and the invocation mechanism determines
the function context value:
– When invoked as a simple function, the context is the global object (window).
– When invoked as a method, the context is the object owning the method.
– When invoked as a constructor, the context is a newly allocated object.
– When invoked via the apply() or call() methods of the function, the context
can be whatever the heck we want.
How can we “fool” methods into operating on objects that aren’t the object that they’re methods for?
By controlling what function context is passed to a function invocation, we can “fool” methods into operating on objects that aren’t the object that they’re methods for. This can be useful for leveraging already existing methods on objects like Array and Math to operate on our own data.
What is a gotcha for javascript prototypes?
1. Extending the Object Object prototype -> every object would have the change
2. extending the the Number object -> literals can give problems to browsers
3. arrays ie and the length property for arrays for example
What are the two purposes a function can serve?
as normal funcions and as constructors
How do you get a reference to the currently executing function?
arguments.callee
How do you test constructors
The instanceof operator for a constructed object tests for its constructor.
How do you test if someone called a function as a constructor from with that function
if (!(this instanceof arguments.callee)) {
return new User(first,last);
}
What should a custom event system should have the ability to do?
1. add event listeners
2. remove event listners
3. event object
Example of Memoizing (caching) DOM elements
function getElements(name) {
if (!getElements.cache) getElements.cache = {};
return getElements.cache[name] = getElements.cache[name] ||
document.getElementsByTagName(name);
}
Example of Simulating array-like methods on an object
var elems = {
length: 0,
add: function(elem){
Array.prototype.push.call(this, elem);
},
gather: function(id){
this.add(document.getElementById(id));
}
};
Example of Generic min() and max() functions for arrays
function smallest(array){
return Math.min.apply(Math, array);
}
function largest(array){
return Math.max.apply(Math, array);
}
Example of using timers to break up long running tasks using a central Timer
var timers = {
timerID: 0,
timers: [],
add: function(fn) {
this.timers.push(fn);
},
start: function() {
if (this.timerID) return;
(function runNext() {
if (timers.timers.length > 0) {
for (var i = 0; i < timers.timers.length; i++) {
if (timers.timers[i]() === false) {
timers.timers.splice(i,1);
i--;
}
}
timers.timerID = setTimeout(runNext, 0);
}
})();
},
stop: function() {
clearTimeout(this.timerID);
this.timerID = 0;
}
};