Did you guys ever take notes?
I remember back when I was learning how anonymous functions worked in Javascript I actually opened notepad and threw notes in their that i would review. Share any notes here, who knows, maybe the tricks you used to teach your newbie self will help others. I'll be adding to this as I have tons of PHP and JS notes on my older system. I will have to organize them for you though, I use to throw shit around like monkeys
HTML'S RANDOM NOTES (JS)
Javascript has a function dataType.
IE: assisgn a variable a function
Code:
var doSomething = function (param, param2){
alert("anonymous function!");
};
__________________________________________________ ____
IE: Pass a function a function
Code:
var doSomething = function (param, param2, fn){
return fn(param, param3);
};
Code:
//The function we're going to pass to our anonymous function doSomething
function sum(param, param2){
return param + param2;
}
//Pass the function we want to use.
doSomething(4, 5, sum);
__________________________________________________ ____
IE: Defining a function as a parameter.
*Note - Imagine that doSomething has THREE params upon instantiation.
Code:
var bar = doSomething(param, param2, function(param, param2){
return param * param2;
});
_______
_______________________________________________
Immediately invoked function. Immediately invoke a function when you write code and
you no longer have to worry about global variables, protecting your code from being
overwritten or misused.
Code:
var foo = "Sup broski!"; //bad
(function (){
var foo = "hello, window!"; //good
alert(foo);
}());
alert(foo);