SlideShare a Scribd company logo
1 of 82
Download to read offline
FRONT END DEVELOPMENT
by Sergey N. Bolshchikov
The Important Parts
3 hours of
wasting my time?
Let's find out
LET'S FIND OUT
1. Is it possible to do shadows with CSS?
LET'S FIND OUT
1. Is it possible to do shadows with CSS?
2. Who can write such function?
var result = addNumbers(2)(3);
LET'S FIND OUT
1. Is it possible to do shadows with CSS?
2. Who can write such function?
var result = addNumbers(2)(3);
3. Who can define "this"?
LET'S FIND OUT
1. Is it possible to do shadows with CSS?
2. Who can write such function?
var result = addNumbers(2)(3);
3. Who can define "this"?
4. How to call a function after completion of
two async functions together?
OUTLINE
I. CSS
1. Basics
2. CSS3
3. LESS
II. JavaScript
1. Functions: objects
2. Lexical scope: closures, module pattern
3. Execution contexts and "this" value
III. Tools and Libraries
1. RequireJS
2. jQuery
3. Promises
4. Chrome Dev Tools
CSS
CSS :: SELECTORS
Selector Description Example
*
Matches any element.
E Matches any E element (i.e., an
element of type E).
a
E F Matches any F element that is a
descendant of an E element.
div a
E > F Matches any F element that is a
child of an element E.
div > a
E:first-child Matches element E when E is the
first child of its parent.
li:first-child
E:link
E:visited
Matches element E if E is the source
anchor of a hyperlink of which the
target is not yet visited (:link) or
already visited (:visited).
a:link
a:visited
CSS :: SELECTORS (cont.)
Selector Description Example
E:active
E:hover
E:focus
Matches E during certain user
actions.
a:active
a:hover
a:focus
E + F Matches any F element immediately
preceded by a sibling element E.
div + div
E[foo] Matches any E element with the
"foo" attribute set (whatever the
value).
div[data-id]
E[foo="warning"] Matches any E element whose "foo"
attribute value is exactly equal to
"warning".
input[type=”text”]
DIV.warning Language specific. (In HTML, the
same as DIV[class~="warning"].)
div.navigation
E#myid Matches any E element with ID equal
to "myid".
div#main
CSS :: BOX MODEL
CSS :: MORE
● display: [none, block, inline, table, inline-
block...],
● position: [absolute, fixed, relative],
● top: [number],
● left: [number],
● float: [left, right, none]
● font: size, weight, family
CSS :: CSS3
● border-radius
● box-shadow
● gradients
● multiple columns
● transformations
● animation
http://jsbin.com/udimij/1/edit
LESS
LESS :: WHY?
● CSS is too much writing
.nav {}
.nav ul {}
.nav ul li {}
● No validation
● Declarative
LESS :: WHAT?
LESS extends CSS with dynamic behavior
such as variables, mixins, operations and
functions.
LESS :: NESTING
.nav {
ul {
...
li {
...
}
}
}
LESS :: VARIABLES
@color: #4D926F;
#header {
color: @color;
}
h2 {
color: @color;
}
#header {
color: #4D926F;
}
h2 {
color: #4D926F;
}
LESS :: MIXINS
.border-radius (@radius) {
border-radius: @radius;
-moz-border-radius: @radius;
-webkit-border-radius: @radius;
}
#header {
.border-radius(4px);
}
.button {
.border-radius(6px);
}
#header {
border-radius: 4px;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
}
.button {
border-radius: 4px;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
}
FUNCTIONS
in
JAVASCRIPT
FUNCTION
is an
OBJECT
FUNCTIONS :: OBJECTS
function foo (x) {
return x + 1;
}
function bar (y) {
return y * 2;
}
var myFuncs = [foo, bar];
myFuncs[0](2) // 3
FUNCTIONS :: OBJECTS
var callFirst = function (x) {
return x + 1;
}
var callSecond = function (f, x) {
return f(f(x));
}
var attempt = callSecond(callFirst, 2); // 4
FUNCTIONS :: OBJECTS
var makeFunc = function () {
var addOne = function (x) {
return x + 1;
}
return addOne;
}
var f = makeFunc();
f(3); // 4
LEXICAL
ENVIRONMENT
FUNCTIONS :: LEXICAL ENV :: def
Definition:
A Lexical Environment is a specification type used to define
the association of Identifiers to specific variables and
functions based upon the lexical nesting structure of
ECMAScript code.
FUNCTIONS :: LEXICAL ENV :: wtf
function () {
...
function () {
...
return;
}
return ;
}
Lexical Env Outers
Lexical Env Inner
FUNCTIONS :: LEXICAL ENV :: nesting
function createIncreaser () {
var accumulator = 0;
var increaser = function () {
return accumulator += 2;
};
return increaser;
}
var inc = createIncreaser();
console.log(inc()); // 2
console.log(inc()); // 4
console.log(inc()); // 6
FUNCTIONS :: LEXICAL ENV :: closure
function createIncreaser () {
var accumulator = 0;
var increaser = function () {
return accumulator += 2;
};
return increaser;
}
var inc = createIncreaser();
console.log(inc()); // 2
console.log(inc()); // 4
console.log(inc()); // 6
env
code block
FUNCTIONS :: LEXICAL ENV :: module pattern
// not a constructor
var myModule = (function (projId) {
var moduleName, projectorId;
moduleName = 'toolbar';
projectorId = projId;
return {
init: function () {
console.log(moduleName);
},
tickUpdate: function () {}
};
})();
myModule.init() // "toolbar"
myModule.moduleName // undefined
PROBLEM
<div>
I am div 1
</div>
<div>
I am div 2
</div>
<div>
I am div 3
</div>
PROBLEM
<div>
I am div 1
</div>
<div>
I am div 2
</div>
<div>
I am div 3
</div>
var i, divs, len;
i = 0;
divs=document.getElementsByTagName('div');
len = divs.length;
for (i; i < len; i += 1) {
divs[i].addEventListener('click',
function () {
alert('I am div ' + i);
}, false)
}
http://jsbin.com/acoceb/1/edit
PROBLEM
environment
var i
event
handler 1
event
handler 2
event
handler 3
PROBLEM
<div>
I am div 1
</div>
<div>
I am div 2
</div>
<div>
I am div 3
</div>
var i, divs, len;
i = 0;
divs = document.getElementsByTagName
('div');
len = divs.length;
for (i; i < len; i += 1) {
(function (id) {
divs[i].addEventListener('click',
function () {
alert("I am div " + (id + 1));
}, false);
})(i);
}
http://jsbin.com/acoceb/5/edit
PROBLEM
environment
event
handler 1
event
handler 2
event
handler 3
var i var i var i
EXECUTION
CONTEXT
FUNCTIONS :: EXECUTION
this.javascript !== this.java
this.javascript !== self.python
FUNCTIONS :: EXECUTION CONTEXT
Every line of JavaScript code is run in an
“execution context.”
ExecCont = {
LexicalEnv: {},
VarEnv: {},
ThisBinding: {}
}
FUNCTIONS :: EXECUTABLE CODE TYPES
● Global code
alert("hello world");
● Function code
function callMe () {
alert('hello world');
}
● Eval code
FUNCTIONS :: GLOBAL CONTEXT
var a = 1,
b = 3
c = a + b;
alert(c); // 4
alert(this); // window
FUNCTIONS :: FUNC CONTEXT :: method
var a = {
b: function() {
return this;
}
};
a.b(); //a;
a['b'](); //a;
var c = {};
c.d = a.b;
c.d(); //c
FUNCTIONS :: FUNC CONTEXT :: function
function a () {
return this;
}
var A = a(); // window
FUNCTIONS :: FUNC CONTEXT :: function
var a = {
b: function() {
return this;
}
};
var foo = a.b;
foo(); //window
FUNCTIONS :: FUNC CONTEXT :: function
var a = {
b: function() {
var c = function() {
return this;
};
return c();
}
};
a.b(); //window
FUNCTIONS :: FUNC CONTEXT :: call
function t() {
return [].slice.call(arguments, 1);
}
var upd = t(1,2,3,4,5);
// [2,3,4,5]
fun.call(thisArg[, arg1[, arg2[, ...]]])
FUNCTIONS :: FUNC CONTEXT :: apply
function t() {
return [].slice.apply(arguments, [1]);
}
var upd = t(1,2,3,4,5);
// [2,3,4,5]
fun.apply(thisArg[, argsArray])
function Builder () {
this.name = 'Arnold';
}
var b = new Builder();
// b = {
// name: 'Arnold'
// }
FUNCTIONS :: FUNC CONTEXT :: new
FUNCTIONS :: FUNC CONTEXT :: reference
Execution Context Syntax of function call Value of this
Global n/a global object (e.g. window)
Function
Method call:
myObject.foo();
myObject
Function
Baseless function call:
foo();
global object (e.g. window)
(undefined in strict mode)
Function
Using call:
foo.call(context, myArg);
context
Function
Using apply:
foo.apply(context, [myArgs]);
context
Function
Constructor with new:
var newFoo = new Foo();
the new instance
(e.g. newFoo)
Evaluation n/a value of this in parent context
source: http://javascriptweblog.wordpress.com/2010/08/30/understanding-javascripts-this/
TOOLS
REQUIREJS
REQUIREJS :: WHY?
● Web sites are turning into Web apps
● Code complexity grows as the site gets
bigger
● Assembly gets harder
● Developer wants discrete JS files/modules
● JavaScript doesn't have import yet
source: http://requirejs.org/docs/why.html
REQUIREJS :: WHAT?
RequireJS
is
an AMD JavaScript file
and module loader.
REQUIREJS :: HOW? :: define
define();
REQUIREJS :: HOW? :: define
define([]);
REQUIREJS :: HOW? :: define
define(['sandbox', './views/View']);
REQUIREJS :: HOW? :: define
define(['sandbox', './views/View'],
function () {
});
REQUIREJS :: HOW? :: define
define(['sandbox', './views/View'],
function (sandbox, View) {
});
REQUIREJS :: HOW? :: define
define(['sandbox', './views/View'],
function (sandbox, View) {
var Module = function () { }
return Module;
});
REQUIREJS :: HOW? :: define
define(['sandbox', './views/View'],
function (sandbox, View) {
var Module = function () {
var views = [];
this.init = function () { };
this.tickUpdate = function () { }
}
return Module;
});
REQUIREJS :: HOW? :: define
define(['sandbox', './views/View'],
function (sandbox, View) {
var Module = function () {
var views = [];
this.init = function () {};
this.tickUpdate = function () {
this.views.push(View.create());
}
}
return Module;
});
REQUIREJS :: HOW? :: config
require.config({
shim: {
'ember': {
deps: ['jquery', 'handlebars'],
exports: 'Ember'
}
},
paths: {
...
jquery: 'libs/jquery-1.8.2',
tick_mngr: 'managers/tick',
ember: 'libs/ember-1.0.0-rc.1',
...
}
})
JQUERY
JQUERY :: SELECTORS
$(selector).method()
For example, $(‘#list’) will return the elements which has the attribute id=”list”.
For more, see http://api.jquery.com/category/selectors/.
JQUERY :: DOM MANIPULATIONS
● $(selector).html()
● $(selector).append(html)
● $(selector).remove()
● $(selector).attr('myAttr', 'value')
● $(selector).removeAttr('myAttr')
● $(selector).css('width', 40)
● $(selector).addClass('my-class')
● $(selector).removeClass('my-class')
● $(selector).text()
● $(selector).val()
JQUERY :: AJAX
$.ajax({
url: ‘/api/posts’
type: ‘POST’,
data: {},
success: function () {},
error: function () {}
});
JQUERY :: EVENTS
● $(selector).click(function () {})
● $(selector).dblclick(function () {})
● $(selector).mousedown(function () {})
● $(selector).mouseup(function () {})
● $(selector).mouseover(function () {})
● $(selector).mouseenter(function () {})
● $(selector).mouseleave(function () {})
● $(selector).on(eventName,
function () {})
● $(selector).off(eventName,
function () {})
PROMISES
REMINDER :: async nature
function getData() {
var data;
$.ajax({
url: 'https://api.github.com/users/bolshchikov',
type: 'GET',
success: function (response) {
data = response;
}
});
return data;
}
var myData = getData(); // ???
http://jsbin.com/imatun/2/edit
REMINDER :: async nature
function getData() {
var data;
$.ajax({
url: 'https://api.github.com/users/bolshchikov',
type: 'GET',
success: function (response) {
data = response;
}
});
return data;
}
var myData = getData(); // undefined
http://jsbin.com/imatun/2/edit
TOOLS :: PROMISES :: pyramid of doom
startChannel(function (data) {
drawLayout(function () {
startFirstModule(function () {
...
});
});
});
TOOLS :: PROMISES :: parallel
startChannel(function (data) {
drawLayout(function () {
startFirstModule(function () {
...
});
});
});
1
1
2
TOOLS :: PROMISES :: def
In computer science, future, promise, and delay refer to
constructs used for synchronizing in some concurrent
programming languages. They describe an object that acts as a
proxy for a result that is initially unknown, usually because the
computation of its value is yet incomplete.
The term promise was proposed in 1976 by Daniel P. Friedman
and David Wise,[1] [...]
The terms future, promise, and delay are often used
interchangeably, although some differences in usage between
future and promise are treated below. Setting the value of a
future is also called resolving, fulfilling, or binding it.
Source: http://en.wikipedia.org/wiki/Futures_and_promises
source: http://blog.mediumequalsmessage.com/promise-deferred-objects-in-javascript-pt1-theory-and-semantics
TOOLS :: PROMISES :: Deferred Object
jQuery.Deferred() A constructor that creates a new Deferred object, can take an optional
initFunction parameter that will be called right after the deferred has
been constructed.
jQuery.when() A way to execute callback functions based on one or more objects that
represent asynchronous tasks.
jQuery.ajax() Performs an asynchronous Ajax requests where the jqXHR objects
returned by $.ajax() implement the Promise interface, giving them all
the properties, methods, and behaviour of a Promise.
deferred.resolve(arg1, arg2, ...) Resolve a Deferred object and call any 'done' Callback with the given
arguments.
deferred.reject(arg1, arg2, ...) Reject a Deferred object and call any 'fail' Callback with the given
arguments.
deferred.promise() Returns a promise, that is an immutable view of the deferred object: the
promise can be passed around safely since the underlying deferred
cannot be resolved or rejected through it.
TOOLS :: PROMISES :: Promise Object
deferred.then(resolveCallback,
rejectCallback)
Handlers to be called when the Deferred object is resolved or
rejected.
deferred.done() Functions or array of functions that are called when the Deferred
object is resolved.
deferred.fail() Functions or array of functions that are called when the Deferred is
rejected.
deferred.isResolved Determine whether a Deferred object has been resolved.
TOOLS :: PROMISES :: side 1
$.when(
// call functions
startChannel(),
drawLayout()
).done(function () {
// do when both are done
initModule.start();
})
TOOLS :: PROMISES :: side 2
function drawLayout () {
var dfd = $.Deferred();
function loadSettings() {
// do some ajax request;
}
function validate() {
...
// in case validation failed
dfd.reject();
}
function render() {
// render
return dfd.resolve();
}
return dfd.promise();
}
CHROME
DEVELOPER
TOOLS
CHROME DEV TOOLS :: OPEN
● F12 (Windows)
● Alt + Cmd + i (Mac)
● View > Developer > Developer Tools (Everywhere)
● Mouse right click > Inspect Element (Everywhere)
source: http://www.html5rocks.com/en/tutorials/developertools/part1/
CHROME DEV TOOLS :: TABS
1. Elements: edit HTML, CSS, events
2. Resources: local storage, cookies
3. Network: xhr requests, their size, headers...
4. Source: js editing, debugging, breakpoints
5. Timeline: performance, memory
6. Profile: performance
7. Audits
8. Console
to be continued...
PAUSE

More Related Content

What's hot

Difference between java script and jquery
Difference between java script and jqueryDifference between java script and jquery
Difference between java script and jqueryUmar Ali
 
Java script programs
Java script programsJava script programs
Java script programsITz_1
 
the 5 layers of web accessibility - Open Web Camp II
the 5 layers of web accessibility - Open Web Camp IIthe 5 layers of web accessibility - Open Web Camp II
the 5 layers of web accessibility - Open Web Camp IIDirk Ginader
 
Netvibes UWA workshop at ParisWeb 2007
Netvibes UWA workshop at ParisWeb 2007Netvibes UWA workshop at ParisWeb 2007
Netvibes UWA workshop at ParisWeb 2007Netvibes
 
jQuery Presentation to Rails Developers
jQuery Presentation to Rails DevelopersjQuery Presentation to Rails Developers
jQuery Presentation to Rails DevelopersYehuda Katz
 
JavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM ManipulationJavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM Manipulationborkweb
 
LinkedIn Platform at LeWeb 2010
LinkedIn Platform at LeWeb 2010LinkedIn Platform at LeWeb 2010
LinkedIn Platform at LeWeb 2010Adam Trachtenberg
 
10 java script projects full source code
10 java script projects full source code10 java script projects full source code
10 java script projects full source codeLaurence Svekis ✔
 
Week 4 - jQuery + Ajax
Week 4 - jQuery + AjaxWeek 4 - jQuery + Ajax
Week 4 - jQuery + Ajaxbaygross
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the FinishYehuda Katz
 
jQuery For Developers Stack Overflow Dev Days Toronto
jQuery For Developers Stack Overflow Dev Days TorontojQuery For Developers Stack Overflow Dev Days Toronto
jQuery For Developers Stack Overflow Dev Days TorontoRalph Whitbeck
 
JavaScript and jQuery Basics
JavaScript and jQuery BasicsJavaScript and jQuery Basics
JavaScript and jQuery BasicsKaloyan Kosev
 

What's hot (20)

Java Script
Java ScriptJava Script
Java Script
 
Difference between java script and jquery
Difference between java script and jqueryDifference between java script and jquery
Difference between java script and jquery
 
Introduction to java_script
Introduction to java_scriptIntroduction to java_script
Introduction to java_script
 
Java script programs
Java script programsJava script programs
Java script programs
 
Java script
Java scriptJava script
Java script
 
the 5 layers of web accessibility - Open Web Camp II
the 5 layers of web accessibility - Open Web Camp IIthe 5 layers of web accessibility - Open Web Camp II
the 5 layers of web accessibility - Open Web Camp II
 
JAVA SCRIPT
JAVA SCRIPTJAVA SCRIPT
JAVA SCRIPT
 
Netvibes UWA workshop at ParisWeb 2007
Netvibes UWA workshop at ParisWeb 2007Netvibes UWA workshop at ParisWeb 2007
Netvibes UWA workshop at ParisWeb 2007
 
jQuery Presentation to Rails Developers
jQuery Presentation to Rails DevelopersjQuery Presentation to Rails Developers
jQuery Presentation to Rails Developers
 
PHP 5 Sucks. PHP 5 Rocks.
PHP 5 Sucks. PHP 5 Rocks.PHP 5 Sucks. PHP 5 Rocks.
PHP 5 Sucks. PHP 5 Rocks.
 
JavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM ManipulationJavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM Manipulation
 
LinkedIn Platform at LeWeb 2010
LinkedIn Platform at LeWeb 2010LinkedIn Platform at LeWeb 2010
LinkedIn Platform at LeWeb 2010
 
10 java script projects full source code
10 java script projects full source code10 java script projects full source code
10 java script projects full source code
 
jQuery
jQueryjQuery
jQuery
 
Merb jQuery
Merb jQueryMerb jQuery
Merb jQuery
 
前端概述
前端概述前端概述
前端概述
 
Week 4 - jQuery + Ajax
Week 4 - jQuery + AjaxWeek 4 - jQuery + Ajax
Week 4 - jQuery + Ajax
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
 
jQuery For Developers Stack Overflow Dev Days Toronto
jQuery For Developers Stack Overflow Dev Days TorontojQuery For Developers Stack Overflow Dev Days Toronto
jQuery For Developers Stack Overflow Dev Days Toronto
 
JavaScript and jQuery Basics
JavaScript and jQuery BasicsJavaScript and jQuery Basics
JavaScript and jQuery Basics
 

Viewers also liked

Introduction to React
Introduction to ReactIntroduction to React
Introduction to ReactAustin Garrod
 
React JS and why it's awesome
React JS and why it's awesomeReact JS and why it's awesome
React JS and why it's awesomeAndrew Hull
 
Quick start with React | DreamLab Academy #2
Quick start with React | DreamLab Academy #2Quick start with React | DreamLab Academy #2
Quick start with React | DreamLab Academy #2DreamLab
 
Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017Elyse Kolker Gordon
 
A Brief Introduction to React.js
A Brief Introduction to React.jsA Brief Introduction to React.js
A Brief Introduction to React.jsDoug Neiner
 

Viewers also liked (7)

Introduction to React
Introduction to ReactIntroduction to React
Introduction to React
 
React JS and why it's awesome
React JS and why it's awesomeReact JS and why it's awesome
React JS and why it's awesome
 
Quick start with React | DreamLab Academy #2
Quick start with React | DreamLab Academy #2Quick start with React | DreamLab Academy #2
Quick start with React | DreamLab Academy #2
 
Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017
 
A Brief Introduction to React.js
A Brief Introduction to React.jsA Brief Introduction to React.js
A Brief Introduction to React.js
 
React + Redux for Web Developers
React + Redux for Web DevelopersReact + Redux for Web Developers
React + Redux for Web Developers
 
React js
React jsReact js
React js
 

Similar to Front End Development: The Important Parts

HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyDavid Padbury
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing UpDavid Padbury
 
JavaOne TS-5098 Groovy SwingBuilder
JavaOne TS-5098 Groovy SwingBuilderJavaOne TS-5098 Groovy SwingBuilder
JavaOne TS-5098 Groovy SwingBuilderAndres Almiray
 
CodeMash - Building Rich Apps with Groovy SwingBuilder
CodeMash - Building Rich Apps with Groovy SwingBuilderCodeMash - Building Rich Apps with Groovy SwingBuilder
CodeMash - Building Rich Apps with Groovy SwingBuilderAndres Almiray
 
Smoothing Your Java with DSLs
Smoothing Your Java with DSLsSmoothing Your Java with DSLs
Smoothing Your Java with DSLsintelliyole
 
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra  SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra Sencha
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]GDSC UofT Mississauga
 
Sencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScriptSencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScriptRohan Chandane
 
WebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open webWebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open webpjcozzi
 
Overview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web FrameworkOverview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web FrameworkIndicThreads
 
Scala based Lift Framework
Scala based Lift FrameworkScala based Lift Framework
Scala based Lift Frameworkvhazrati
 
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...GITS Indonesia
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...Doug Jones
 

Similar to Front End Development: The Important Parts (20)

HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
JavaOne TS-5098 Groovy SwingBuilder
JavaOne TS-5098 Groovy SwingBuilderJavaOne TS-5098 Groovy SwingBuilder
JavaOne TS-5098 Groovy SwingBuilder
 
CodeMash - Building Rich Apps with Groovy SwingBuilder
CodeMash - Building Rich Apps with Groovy SwingBuilderCodeMash - Building Rich Apps with Groovy SwingBuilder
CodeMash - Building Rich Apps with Groovy SwingBuilder
 
Smoothing Your Java with DSLs
Smoothing Your Java with DSLsSmoothing Your Java with DSLs
Smoothing Your Java with DSLs
 
Play!ng with scala
Play!ng with scalaPlay!ng with scala
Play!ng with scala
 
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra  SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
 
JavaScript Core
JavaScript CoreJavaScript Core
JavaScript Core
 
"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]
 
Sencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScriptSencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScript
 
WebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open webWebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open web
 
React native
React nativeReact native
React native
 
Overview Of Lift Framework
Overview Of Lift FrameworkOverview Of Lift Framework
Overview Of Lift Framework
 
Overview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web FrameworkOverview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web Framework
 
Scala based Lift Framework
Scala based Lift FrameworkScala based Lift Framework
Scala based Lift Framework
 
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
 
NodeJS
NodeJSNodeJS
NodeJS
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
 
Oojs 1.1
Oojs 1.1Oojs 1.1
Oojs 1.1
 

More from Sergey Bolshchikov

Onboarding for Software Engineers Done Right
Onboarding for Software Engineers Done RightOnboarding for Software Engineers Done Right
Onboarding for Software Engineers Done RightSergey Bolshchikov
 
Microservices on the client side
Microservices on the client sideMicroservices on the client side
Microservices on the client sideSergey Bolshchikov
 
Values & Culture of Continuous Deliver
Values & Culture of Continuous DeliverValues & Culture of Continuous Deliver
Values & Culture of Continuous DeliverSergey Bolshchikov
 
Continuous Delivery for Front-End Engineers
Continuous Delivery for Front-End EngineersContinuous Delivery for Front-End Engineers
Continuous Delivery for Front-End EngineersSergey Bolshchikov
 
Зачем нужен EmberJS, если мне хвататет jQuery
Зачем нужен EmberJS, если мне хвататет jQueryЗачем нужен EmberJS, если мне хвататет jQuery
Зачем нужен EmberJS, если мне хвататет jQuerySergey Bolshchikov
 
Ember Reusable Components and Widgets
Ember Reusable Components and WidgetsEmber Reusable Components and Widgets
Ember Reusable Components and WidgetsSergey Bolshchikov
 
JS Single-Page Web App Essentials
JS Single-Page Web App EssentialsJS Single-Page Web App Essentials
JS Single-Page Web App EssentialsSergey Bolshchikov
 

More from Sergey Bolshchikov (13)

Onboarding for Software Engineers Done Right
Onboarding for Software Engineers Done RightOnboarding for Software Engineers Done Right
Onboarding for Software Engineers Done Right
 
Pragmatic React Workshop
Pragmatic React WorkshopPragmatic React Workshop
Pragmatic React Workshop
 
Microservices on the client side
Microservices on the client sideMicroservices on the client side
Microservices on the client side
 
ES2015 Quiz
ES2015 QuizES2015 Quiz
ES2015 Quiz
 
Talking code: How To
Talking code: How ToTalking code: How To
Talking code: How To
 
Values & Culture of Continuous Deliver
Values & Culture of Continuous DeliverValues & Culture of Continuous Deliver
Values & Culture of Continuous Deliver
 
Protractor: Tips & Tricks
Protractor: Tips & TricksProtractor: Tips & Tricks
Protractor: Tips & Tricks
 
Continuous Delivery for Front-End Engineers
Continuous Delivery for Front-End EngineersContinuous Delivery for Front-End Engineers
Continuous Delivery for Front-End Engineers
 
Зачем нужен EmberJS, если мне хвататет jQuery
Зачем нужен EmberJS, если мне хвататет jQueryЗачем нужен EmberJS, если мне хвататет jQuery
Зачем нужен EmberJS, если мне хвататет jQuery
 
Ember Reusable Components and Widgets
Ember Reusable Components and WidgetsEmber Reusable Components and Widgets
Ember Reusable Components and Widgets
 
AngularJS Basics with Example
AngularJS Basics with ExampleAngularJS Basics with Example
AngularJS Basics with Example
 
Backbone Basics with Examples
Backbone Basics with ExamplesBackbone Basics with Examples
Backbone Basics with Examples
 
JS Single-Page Web App Essentials
JS Single-Page Web App EssentialsJS Single-Page Web App Essentials
JS Single-Page Web App Essentials
 

Recently uploaded

Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 

Recently uploaded (20)

Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 

Front End Development: The Important Parts

  • 1. FRONT END DEVELOPMENT by Sergey N. Bolshchikov The Important Parts
  • 4. LET'S FIND OUT 1. Is it possible to do shadows with CSS?
  • 5. LET'S FIND OUT 1. Is it possible to do shadows with CSS? 2. Who can write such function? var result = addNumbers(2)(3);
  • 6. LET'S FIND OUT 1. Is it possible to do shadows with CSS? 2. Who can write such function? var result = addNumbers(2)(3); 3. Who can define "this"?
  • 7. LET'S FIND OUT 1. Is it possible to do shadows with CSS? 2. Who can write such function? var result = addNumbers(2)(3); 3. Who can define "this"? 4. How to call a function after completion of two async functions together?
  • 8. OUTLINE I. CSS 1. Basics 2. CSS3 3. LESS II. JavaScript 1. Functions: objects 2. Lexical scope: closures, module pattern 3. Execution contexts and "this" value III. Tools and Libraries 1. RequireJS 2. jQuery 3. Promises 4. Chrome Dev Tools
  • 9. CSS
  • 10. CSS :: SELECTORS Selector Description Example * Matches any element. E Matches any E element (i.e., an element of type E). a E F Matches any F element that is a descendant of an E element. div a E > F Matches any F element that is a child of an element E. div > a E:first-child Matches element E when E is the first child of its parent. li:first-child E:link E:visited Matches element E if E is the source anchor of a hyperlink of which the target is not yet visited (:link) or already visited (:visited). a:link a:visited
  • 11. CSS :: SELECTORS (cont.) Selector Description Example E:active E:hover E:focus Matches E during certain user actions. a:active a:hover a:focus E + F Matches any F element immediately preceded by a sibling element E. div + div E[foo] Matches any E element with the "foo" attribute set (whatever the value). div[data-id] E[foo="warning"] Matches any E element whose "foo" attribute value is exactly equal to "warning". input[type=”text”] DIV.warning Language specific. (In HTML, the same as DIV[class~="warning"].) div.navigation E#myid Matches any E element with ID equal to "myid". div#main
  • 12. CSS :: BOX MODEL
  • 13. CSS :: MORE ● display: [none, block, inline, table, inline- block...], ● position: [absolute, fixed, relative], ● top: [number], ● left: [number], ● float: [left, right, none] ● font: size, weight, family
  • 14. CSS :: CSS3 ● border-radius ● box-shadow ● gradients ● multiple columns ● transformations ● animation http://jsbin.com/udimij/1/edit
  • 15. LESS
  • 16. LESS :: WHY? ● CSS is too much writing .nav {} .nav ul {} .nav ul li {} ● No validation ● Declarative
  • 17. LESS :: WHAT? LESS extends CSS with dynamic behavior such as variables, mixins, operations and functions.
  • 18. LESS :: NESTING .nav { ul { ... li { ... } } }
  • 19. LESS :: VARIABLES @color: #4D926F; #header { color: @color; } h2 { color: @color; } #header { color: #4D926F; } h2 { color: #4D926F; }
  • 20. LESS :: MIXINS .border-radius (@radius) { border-radius: @radius; -moz-border-radius: @radius; -webkit-border-radius: @radius; } #header { .border-radius(4px); } .button { .border-radius(6px); } #header { border-radius: 4px; -moz-border-radius: 4px; -webkit-border-radius: 4px; } .button { border-radius: 4px; -moz-border-radius: 4px; -webkit-border-radius: 4px; }
  • 23. FUNCTIONS :: OBJECTS function foo (x) { return x + 1; } function bar (y) { return y * 2; } var myFuncs = [foo, bar]; myFuncs[0](2) // 3
  • 24. FUNCTIONS :: OBJECTS var callFirst = function (x) { return x + 1; } var callSecond = function (f, x) { return f(f(x)); } var attempt = callSecond(callFirst, 2); // 4
  • 25. FUNCTIONS :: OBJECTS var makeFunc = function () { var addOne = function (x) { return x + 1; } return addOne; } var f = makeFunc(); f(3); // 4
  • 27. FUNCTIONS :: LEXICAL ENV :: def Definition: A Lexical Environment is a specification type used to define the association of Identifiers to specific variables and functions based upon the lexical nesting structure of ECMAScript code.
  • 28. FUNCTIONS :: LEXICAL ENV :: wtf function () { ... function () { ... return; } return ; } Lexical Env Outers Lexical Env Inner
  • 29. FUNCTIONS :: LEXICAL ENV :: nesting function createIncreaser () { var accumulator = 0; var increaser = function () { return accumulator += 2; }; return increaser; } var inc = createIncreaser(); console.log(inc()); // 2 console.log(inc()); // 4 console.log(inc()); // 6
  • 30. FUNCTIONS :: LEXICAL ENV :: closure function createIncreaser () { var accumulator = 0; var increaser = function () { return accumulator += 2; }; return increaser; } var inc = createIncreaser(); console.log(inc()); // 2 console.log(inc()); // 4 console.log(inc()); // 6 env code block
  • 31. FUNCTIONS :: LEXICAL ENV :: module pattern // not a constructor var myModule = (function (projId) { var moduleName, projectorId; moduleName = 'toolbar'; projectorId = projId; return { init: function () { console.log(moduleName); }, tickUpdate: function () {} }; })(); myModule.init() // "toolbar" myModule.moduleName // undefined
  • 32. PROBLEM <div> I am div 1 </div> <div> I am div 2 </div> <div> I am div 3 </div>
  • 33. PROBLEM <div> I am div 1 </div> <div> I am div 2 </div> <div> I am div 3 </div> var i, divs, len; i = 0; divs=document.getElementsByTagName('div'); len = divs.length; for (i; i < len; i += 1) { divs[i].addEventListener('click', function () { alert('I am div ' + i); }, false) } http://jsbin.com/acoceb/1/edit
  • 35. PROBLEM <div> I am div 1 </div> <div> I am div 2 </div> <div> I am div 3 </div> var i, divs, len; i = 0; divs = document.getElementsByTagName ('div'); len = divs.length; for (i; i < len; i += 1) { (function (id) { divs[i].addEventListener('click', function () { alert("I am div " + (id + 1)); }, false); })(i); } http://jsbin.com/acoceb/5/edit
  • 38. FUNCTIONS :: EXECUTION this.javascript !== this.java this.javascript !== self.python
  • 39. FUNCTIONS :: EXECUTION CONTEXT Every line of JavaScript code is run in an “execution context.” ExecCont = { LexicalEnv: {}, VarEnv: {}, ThisBinding: {} }
  • 40. FUNCTIONS :: EXECUTABLE CODE TYPES ● Global code alert("hello world"); ● Function code function callMe () { alert('hello world'); } ● Eval code
  • 41. FUNCTIONS :: GLOBAL CONTEXT var a = 1, b = 3 c = a + b; alert(c); // 4 alert(this); // window
  • 42. FUNCTIONS :: FUNC CONTEXT :: method var a = { b: function() { return this; } }; a.b(); //a; a['b'](); //a; var c = {}; c.d = a.b; c.d(); //c
  • 43. FUNCTIONS :: FUNC CONTEXT :: function function a () { return this; } var A = a(); // window
  • 44. FUNCTIONS :: FUNC CONTEXT :: function var a = { b: function() { return this; } }; var foo = a.b; foo(); //window
  • 45. FUNCTIONS :: FUNC CONTEXT :: function var a = { b: function() { var c = function() { return this; }; return c(); } }; a.b(); //window
  • 46. FUNCTIONS :: FUNC CONTEXT :: call function t() { return [].slice.call(arguments, 1); } var upd = t(1,2,3,4,5); // [2,3,4,5] fun.call(thisArg[, arg1[, arg2[, ...]]])
  • 47. FUNCTIONS :: FUNC CONTEXT :: apply function t() { return [].slice.apply(arguments, [1]); } var upd = t(1,2,3,4,5); // [2,3,4,5] fun.apply(thisArg[, argsArray])
  • 48. function Builder () { this.name = 'Arnold'; } var b = new Builder(); // b = { // name: 'Arnold' // } FUNCTIONS :: FUNC CONTEXT :: new
  • 49. FUNCTIONS :: FUNC CONTEXT :: reference Execution Context Syntax of function call Value of this Global n/a global object (e.g. window) Function Method call: myObject.foo(); myObject Function Baseless function call: foo(); global object (e.g. window) (undefined in strict mode) Function Using call: foo.call(context, myArg); context Function Using apply: foo.apply(context, [myArgs]); context Function Constructor with new: var newFoo = new Foo(); the new instance (e.g. newFoo) Evaluation n/a value of this in parent context source: http://javascriptweblog.wordpress.com/2010/08/30/understanding-javascripts-this/
  • 50. TOOLS
  • 52. REQUIREJS :: WHY? ● Web sites are turning into Web apps ● Code complexity grows as the site gets bigger ● Assembly gets harder ● Developer wants discrete JS files/modules ● JavaScript doesn't have import yet source: http://requirejs.org/docs/why.html
  • 53. REQUIREJS :: WHAT? RequireJS is an AMD JavaScript file and module loader.
  • 54. REQUIREJS :: HOW? :: define define();
  • 55. REQUIREJS :: HOW? :: define define([]);
  • 56. REQUIREJS :: HOW? :: define define(['sandbox', './views/View']);
  • 57. REQUIREJS :: HOW? :: define define(['sandbox', './views/View'], function () { });
  • 58. REQUIREJS :: HOW? :: define define(['sandbox', './views/View'], function (sandbox, View) { });
  • 59. REQUIREJS :: HOW? :: define define(['sandbox', './views/View'], function (sandbox, View) { var Module = function () { } return Module; });
  • 60. REQUIREJS :: HOW? :: define define(['sandbox', './views/View'], function (sandbox, View) { var Module = function () { var views = []; this.init = function () { }; this.tickUpdate = function () { } } return Module; });
  • 61. REQUIREJS :: HOW? :: define define(['sandbox', './views/View'], function (sandbox, View) { var Module = function () { var views = []; this.init = function () {}; this.tickUpdate = function () { this.views.push(View.create()); } } return Module; });
  • 62. REQUIREJS :: HOW? :: config require.config({ shim: { 'ember': { deps: ['jquery', 'handlebars'], exports: 'Ember' } }, paths: { ... jquery: 'libs/jquery-1.8.2', tick_mngr: 'managers/tick', ember: 'libs/ember-1.0.0-rc.1', ... } })
  • 64. JQUERY :: SELECTORS $(selector).method() For example, $(‘#list’) will return the elements which has the attribute id=”list”. For more, see http://api.jquery.com/category/selectors/.
  • 65. JQUERY :: DOM MANIPULATIONS ● $(selector).html() ● $(selector).append(html) ● $(selector).remove() ● $(selector).attr('myAttr', 'value') ● $(selector).removeAttr('myAttr') ● $(selector).css('width', 40) ● $(selector).addClass('my-class') ● $(selector).removeClass('my-class') ● $(selector).text() ● $(selector).val()
  • 66. JQUERY :: AJAX $.ajax({ url: ‘/api/posts’ type: ‘POST’, data: {}, success: function () {}, error: function () {} });
  • 67. JQUERY :: EVENTS ● $(selector).click(function () {}) ● $(selector).dblclick(function () {}) ● $(selector).mousedown(function () {}) ● $(selector).mouseup(function () {}) ● $(selector).mouseover(function () {}) ● $(selector).mouseenter(function () {}) ● $(selector).mouseleave(function () {}) ● $(selector).on(eventName, function () {}) ● $(selector).off(eventName, function () {})
  • 69. REMINDER :: async nature function getData() { var data; $.ajax({ url: 'https://api.github.com/users/bolshchikov', type: 'GET', success: function (response) { data = response; } }); return data; } var myData = getData(); // ??? http://jsbin.com/imatun/2/edit
  • 70. REMINDER :: async nature function getData() { var data; $.ajax({ url: 'https://api.github.com/users/bolshchikov', type: 'GET', success: function (response) { data = response; } }); return data; } var myData = getData(); // undefined http://jsbin.com/imatun/2/edit
  • 71. TOOLS :: PROMISES :: pyramid of doom startChannel(function (data) { drawLayout(function () { startFirstModule(function () { ... }); }); });
  • 72. TOOLS :: PROMISES :: parallel startChannel(function (data) { drawLayout(function () { startFirstModule(function () { ... }); }); }); 1 1 2
  • 73. TOOLS :: PROMISES :: def In computer science, future, promise, and delay refer to constructs used for synchronizing in some concurrent programming languages. They describe an object that acts as a proxy for a result that is initially unknown, usually because the computation of its value is yet incomplete. The term promise was proposed in 1976 by Daniel P. Friedman and David Wise,[1] [...] The terms future, promise, and delay are often used interchangeably, although some differences in usage between future and promise are treated below. Setting the value of a future is also called resolving, fulfilling, or binding it. Source: http://en.wikipedia.org/wiki/Futures_and_promises
  • 75. TOOLS :: PROMISES :: Deferred Object jQuery.Deferred() A constructor that creates a new Deferred object, can take an optional initFunction parameter that will be called right after the deferred has been constructed. jQuery.when() A way to execute callback functions based on one or more objects that represent asynchronous tasks. jQuery.ajax() Performs an asynchronous Ajax requests where the jqXHR objects returned by $.ajax() implement the Promise interface, giving them all the properties, methods, and behaviour of a Promise. deferred.resolve(arg1, arg2, ...) Resolve a Deferred object and call any 'done' Callback with the given arguments. deferred.reject(arg1, arg2, ...) Reject a Deferred object and call any 'fail' Callback with the given arguments. deferred.promise() Returns a promise, that is an immutable view of the deferred object: the promise can be passed around safely since the underlying deferred cannot be resolved or rejected through it.
  • 76. TOOLS :: PROMISES :: Promise Object deferred.then(resolveCallback, rejectCallback) Handlers to be called when the Deferred object is resolved or rejected. deferred.done() Functions or array of functions that are called when the Deferred object is resolved. deferred.fail() Functions or array of functions that are called when the Deferred is rejected. deferred.isResolved Determine whether a Deferred object has been resolved.
  • 77. TOOLS :: PROMISES :: side 1 $.when( // call functions startChannel(), drawLayout() ).done(function () { // do when both are done initModule.start(); })
  • 78. TOOLS :: PROMISES :: side 2 function drawLayout () { var dfd = $.Deferred(); function loadSettings() { // do some ajax request; } function validate() { ... // in case validation failed dfd.reject(); } function render() { // render return dfd.resolve(); } return dfd.promise(); }
  • 80. CHROME DEV TOOLS :: OPEN ● F12 (Windows) ● Alt + Cmd + i (Mac) ● View > Developer > Developer Tools (Everywhere) ● Mouse right click > Inspect Element (Everywhere) source: http://www.html5rocks.com/en/tutorials/developertools/part1/
  • 81. CHROME DEV TOOLS :: TABS 1. Elements: edit HTML, CSS, events 2. Resources: local storage, cookies 3. Network: xhr requests, their size, headers... 4. Source: js editing, debugging, breakpoints 5. Timeline: performance, memory 6. Profile: performance 7. Audits 8. Console