This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Both ways to create functions use the function keyword, so the difference between them aren't immediately apparent. | |
//****************** | |
// Declarations | |
//****************** | |
// Variable declarations and functions declarations operate similiarly. They start with a keywords (var or function), followed by an identifier. | |
// Function declarations add lists of arguments in parentheses followed by blocks in curly braces. | |
function functionName(arg1, arg2, argN) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//*********************************** | |
// TextContent vs innerText | |
//*********************************** | |
// Innertext returns with a line breaks in it because it behaves like you'd copy and pasted the element, and becasue div is block level it put "World" on a new line. innerText is styles dependant, so will therefore have to check the style sheet | |
var div = document.createElement('div'); | |
div.style.background = 'url(img.png)'; | |
div.innerHTML = "hello <div>world</div>"; | |
document.body.appendChild(div); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Alternative to setInterval | |
//Set interval will run the function doStuff() every 100ms regardless if doStuff has finished. | |
setInterval(function(){ | |
doStuff(); | |
},100); | |
//Alternatively you can use argements.callee after doStuff(); which will is wrapped in a self invoking anyonomous self invoking function | |
(function(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Bad | |
var myObj = { | |
specialFunction: function () { | |
}, | |
anotherSpecialFunction: function () { | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JavaScript has function scope only | |
javascript is compiled | |
tokens/lexing? | |
declarations are compiled | |
implicit declation argument | |
start using strict mode, es6 ***NEW RULE*** | |
always name your function | |
so you canc call the function within its self, purpose of recusion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---- | |
// Sass (v3.3.4) | |
// Compass (v1.0.0.alpha.18) | |
// ---- | |
.icon-country_x32 { | |
background-image: url(../images/header/spritesheet_x32.png); | |
display:block; | |
width: 48px; | |
height: 32px; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var numbers = ['1','5','4','3','53','16','8']; | |
var accending = function(first,second){ | |
return first - second; | |
} | |
var decending = function(first,second){ | |
return second - first; | |
}; | |
console.log(numbers.sort(decending)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sum(){ | |
var result = 0, | |
i = 0, | |
len = arguments.length; | |
while (i < len){ | |
result += arguments[i]; | |
i++; | |
} | |
return result; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
** Pushing values to an array | |
*/ | |
var heroCallList = [ ]; | |
heroCallList.push("Robin"); | |
heroCallList.push("Batgirl"); | |
heroCallList.push("Nightwing"); | |
console.log(heroCallList); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
http.createServer(function(req,res){ | |
// normalize url by removing querystring, optional | |
var path = req.url.replace(/\/?(?:\?.*)?$/, '').toLowerCase(); | |
switch(path){ | |
case '': | |
res.writeHead(200, {'Content-type': 'text/plain'}); | |
res.end('Homepage'); | |
break; |
OlderNewer