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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
</head> | |
<body> | |
<script src="js/module-1.js"></script> | |
<script src="js/module-2.js"></script> | |
</body> |
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($){ | |
var slides, numSlides, | |
ct = 0, | |
settings = { | |
duration: 500, | |
easing: 'cubic-bezier(1.000, 0.000, 0.000, 1.000)' | |
}; | |
function transition(){ |
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 mod = (function(){ | |
var foo; // set from outside | |
function setItem(val){ | |
val && (foo = val); | |
} | |
return { setItem: setItem }; | |
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
// assumes Q.js has been loaded and available as Q | |
function ajaxCall(){ | |
var dfd = Q.defer(), | |
data = getData({ | |
success: function(response){ | |
dfd.resolve(response); | |
}, | |
error: function(error){ | |
dfd.reject(error); | |
} |
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
/* how to bind `this` for callbacks, good example here too: | |
http://ejohn.org/apps/learn/#84 | |
*/ | |
var uiThing = { | |
parseResponse : function(data){ | |
this.data = data; | |
this.renderUI() | |
}, | |
renderUI : function(){ /* more code */ } |
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
<script> | |
var people = getData(); // however you get your data ... | |
/* structure | |
{ | |
people : [ | |
{ name : "Shiva Khomini Somar Kondar Krohm" }, | |
{ name : ... } |
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
/* for commented version, see https://gist.github.com/4259920/95d6d741d227c274be1ecf5238998c01f3658131 */ | |
function object(o){ | |
function ctor(){} | |
ctor.prototype = o; | |
return new ctor; | |
} | |
function inheritProto(subType,superType){ | |
var prototype = object(superType.prototype); | |
prototype.constructor = subType; |
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
/* ######################### | |
3 - SCOPE - Define a function in a closure, return an object that has access to that function. | |
*/ | |
(function(){ | |
// accessible via the object we return | |
var o = (function(){ | |
// local | |
function _f(){ _log( 'danneh' ); } |
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
/* ######################### | |
2 - SCOPE - CLOSURES | |
hide from global by using a closure | |
*/ | |
(function(n){ // param | |
var myURL = 'google.com'; | |
_log( n === 4 ) // true |
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
// js scoping primer | |
// util | |
var _log = function(){ | |
var slice = [].slice, | |
args = slice.call(arguments), | |
len = args.length, | |
i = 0; | |
for(;i<len;i++) console.log(args[i]) | |
}; |