SlideShare a Scribd company logo
JavaScript
             Core
Nicolas Demengel and François Sarradin
Application
  (client side)     Web Page
                    Animation


                                   HTLM(5)
                                   CSS(3)
Client
                  JavaScript               Server
           JS
         Engine


                      Service
                   (server side)    Embeded
                                    (noSql, ...)
JavaScript
 History

    1996     1998
 1995    1997     2000     2010    What's next?




    ECMA      1.3
   1.0, 1.1         1.5    1.8.5    ES 6
                    ES 3   ES 5    Harmony
      ECMAScript
Brendan Eich 1.2
@ Netscape
JavaScript
JavaScript
Is made of...

   Self     Python          Perl    C/Java



             JavaScript


   ActionScript      Dart      CoffeeScript

Recommended for you

Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript

This document provides an introduction to JavaScript including: - JavaScript is an object-oriented scripting language that is a dialect of ECMAScript. - It was originally designed to add interactivity to HTML pages through dynamic HTML, reacting to events, and data validation. - JavaScript is now heavily used in AJAX-based sites to asynchronously retrieve and display data without reloading pages. - The document discusses JavaScript compatibility issues and provides examples of basic JavaScript concepts like variables, comparisons, repetition, and popup boxes.

Javascript basics for automation testing
Javascript  basics for automation testingJavascript  basics for automation testing
Javascript basics for automation testing

This document provides an overview of basic JavaScript examples and concepts. It covers topics such as writing JavaScript code, variables, conditional statements, functions, loops, events, and error handling. For each topic, it provides short code snippets to demonstrate the concept. It concludes by referencing W3Schools as a resource and thanking the reader.

javascript introductionjavascriptjavascript basics
Oojs 1.1
Oojs 1.1Oojs 1.1
Oojs 1.1

In JS: CLASS <=> Constructor FN new FN() => FN() { this } FN = CLASS (FN = FN, FN = DATA) Objects Prototype / __proto__ Inheritence Rewriting / Augmenting built in objects

oojsjava scriptinheritence
JavaScript

Language
   &
Concepts
JavaScript Syntax
Looks like Java / C++
/* Factorial of n. */
function fact(n) {
  // result of fact
  var result = 1;
  for (var i = 1; i <= n; i++) {
    result *= i;
  }
  return result;
}
JavaScript
Is dynamically typed
var x = 1; // it should be an int
var s = "a"; // string or char?

// it's a function, (type of p?
// does it return something?)
function f(p) { /* ... */ }

var g; // anything (even a function)
JavaScript
Has bad parts
42 == '42' !== 42
if (false) <-> if (null) <-> if (undefined)
false != null == undefined
false !== null !== undefined

return
{
   prop: "val"
};

Use an editor providing validation with JSLint

Recommended for you

Journey of a C# developer into Javascript
Journey of a C# developer into JavascriptJourney of a C# developer into Javascript
Journey of a C# developer into Javascript

this talk is about some of the features of Javascript that are not always good understood by developers like me (that are mainly back-end and work mainly in c# or Java)

newc#javascript
Reactive, component 그리고 angular2
Reactive, component 그리고  angular2Reactive, component 그리고  angular2
Reactive, component 그리고 angular2

This document discusses Reactive programming and Angular 2 components. It introduces Observables and how they can be used to handle asynchronous data streams in a reactive way. It provides examples of creating Observables from events, iterables, and intervals. It also discusses how Observables can be used in Angular 2 to reactively process and display asynchronous data.

angular2
Powerful JavaScript Tips and Best Practices
Powerful JavaScript Tips and Best PracticesPowerful JavaScript Tips and Best Practices
Powerful JavaScript Tips and Best Practices

The document provides 11 powerful JavaScript tips and best practices for programmers, including using short-circuit evaluation to set default values, immediately invoked function expressions to avoid polluting the global namespace, and splice instead of delete to remove array items without leaving undefined holes.

javascriptjsjs best practices
JavaScript
Has few built-in types
●   Boolean    true / false
●   Number     42 21.6 NaN           +∞    -∞
●   String     "hi" 'hello'
●   Date       java-like
●   Regexp     /^.*([0-9]+)w{2,3}$/
●   Object     {prop: val}
●   Array      [a, b]    (it's just an Object)
●   Function   function() {}

● List, Map, Set: where are you? => ES 6
JavaScript
Can define functions
// function declaration (statement)
function f(x) { /* ... */ }

// function expression (operator)
var f = function(x) { /* ... */ };

// Function constructor
var f = new Function('x', '...');
JavaScript
CAN HAZ FUNCTIONZ EVERYWHERE
function compose(f, g) {
  // BTW, this is a closure!
  // more on that later
  return function(x) {
     return f(g(x));
  };
}

compose(square, add_one)(10);
JavaScript
Function: scope & binding
var o = {
   name: "an object",
   logName: function() { log(this.name); }
};

// o.logName can be assigned to a variable:
var logN = o.logName;
logN();

// another way to give o the logName method
function ln() { log(this.name); }
var o = { name: "an object" };
o.logName = ln;

Recommended for you

A Deeper look into Javascript Basics
A Deeper look into Javascript BasicsA Deeper look into Javascript Basics
A Deeper look into Javascript Basics

There are several JavaScript libraries available in the world of web programming. And, as the usage and complexity is increasing day by day, sometimes it becomes very difficult and confusing to understand and create modules using those libraries, especially for those having strong background of Object Oriented Languages. So this one hour session will make an effort to go into the very basics of JavaScript and put a base for writing modular JavaScript code.

htmlcssweb programming
Things about Functional JavaScript
Things about Functional JavaScriptThings about Functional JavaScript
Things about Functional JavaScript

This is the slide for what I shared in JS Group meetup, 2014, Taiwan. It covers what JavaScript could do for making the program more "functional", the benefits, price and the limitation.

functional programmingjavascript
Intro to Javascript
Intro to JavascriptIntro to Javascript
Intro to Javascript

JavaScript is the programming language of the web. It can dynamically manipulate HTML content by changing element properties like innerHTML. Functions allow JavaScript code to run in response to events like button clicks or timeouts. JavaScript uses objects and prototypes to define reusable behaviors and properties for objects. It is an important language for web developers to learn alongside HTML and CSS.

JavaScript
Function: scope & binding
// what is the value of 'this'?
var o = { /* ... */
   logName: function() { log(this.name); }
};

// here it obviously refers to o
o.logName();

// what about the following?
function ln() { log(this.name); }
ln(); // er...
JavaScript
Function: scope & binding
● this = object to wich the function is bound
  ○ By default: the global object (window in browsers)

● Change the way a function is bound to an
  object: apply or call
JavaScript
Function: scope & binding
var o = { nm: "John Doe" };

function say(message) {
  console.log(this.nm + ": " + message);
}

say("hello!"); // ": hello!" (this.nm is undefined)

o.sayIt = say;
o.sayIt("greetings!");   // "John Doe: greetings!"

say.call(o, "yo!");      // "John Doe: yo!"
say.apply(o, ["hi!"]);   // "John Doe: hi!"
JavaScript
Function arguments
(function(x, y) {
   console.log(y); > 'b'

  console.log(arguments.length); > 3
  console.log(arguments[2]); > 'c'

  console.log(arguments.callee);> function(){ }

  console.log(arguments.join); > undefined
  // Array.prototype.join.call(arguments)

})('a', 'b', 'c');

Recommended for you

Protocol-Oriented Programming in Swift
Protocol-Oriented Programming in SwiftProtocol-Oriented Programming in Swift
Protocol-Oriented Programming in Swift

The document discusses protocol-oriented programming in Swift. It begins by comparing protocols in Swift vs Objective-C, noting key differences like protocol inheritance, extensions, default implementations, and associated types in Swift. It then defines protocol-oriented programming as separating public interfaces from implementations using protocols that components communicate through. Examples are provided of using protocols for data types, dependency injection, testing, and real-world UIKit views. Protocol-oriented programming is said to improve reusability, extensibility, and maintainability over inheritance-based approaches.

appleiosswift
Beginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScriptBeginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScript

Slides from my "Object-oriented JavaScript" presentation at CSDN (China Software Developers Network), Beijing, December 2008

stoyannetworkdevelopers
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics

The document provides an overview of JavaScript, covering what it is, its basics, functions, objects, prototypes, scope, asynchronous JavaScript, JSON, debugging tools, performance, events, error handling, and the future of JavaScript. It discusses that JavaScript is an object-oriented scripting language used in web pages that is not tied to specific browsers but makes use of the DOM, BOM, and ECMAScript standards. It also summarizes some of JavaScript's core features like functions, objects, prototypes, and more.

javascript
Prototype-oriented programming
Languages


                 Self

NewtonScript   JavaScript   Lua     Io


                                  Ioke
                                  JVM
Prototype-oriented programming
Instance, prototype, and inheritance
var Vehicle = {
   description: "some vehicle",
   startEngine: function() {
     console.log(this.description
           + " => engine started");
   }
};
// uses Vehicle as proto
var Car = Object.create(Vehicle);
Car.description = "some car";
Car.wheelCount = 4;
Prototype-oriented programming
What do you get?
Vehicle.startEngine();
> "some vehicle => engine started"

Car.startEngine();
> "some car => engine started"

console.log(Vehicle.wheelCount);
> undefined

console.log(Car.wheelCount);
> 4
Prototype-oriented programming
Inheritance manipulation
Car.startEngine = function() {
   console.log("overridden");
}
Car.startEngine(); > "overridden"

// let's delete the car-specific method
delete Car.startEngine;

// parent method is still there
Car.startEngine(); > "some car => engine started"

           JS prototype-based programming
            = delegation (object ⇒ prototype)

Recommended for you

Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript

JavaScript is a scripting language originally designed for web browsers but now used everywhere. It has dynamic typing and supports object-oriented, imperative, and functional programming. JavaScript was created in 1995 and standardized in 1999. It is now the most popular language on GitHub. JavaScript can be used to build interactive web pages, desktop applications, server-side applications, IoT applications, and real-time applications. The core data types in JavaScript are Number, String, Boolean, Object, Function, Array, Date, and Regular Expressions. JavaScript supports features like variables, flow control, error handling, debugging, and JSON for data exchange.

nodejavascriptprogramming
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript

JavaScript language plays a very important role in Web 2.0 application development. JavaScript has its own characteristics different than object-oriented languages and it's not easy for developers to understand. This presentation covers major advanced topics in JavaScript languages, including prototype chain, identifier resolving, "this" keyword, "new" operator, execution context and scope chain and closure. Besides that, it also covers best practices when using JavaScript.

inheritanceprototypejavascript
Javascript tid-bits
Javascript tid-bitsJavascript tid-bits
Javascript tid-bits

An introductory presentation I'm doing at my workplace for other developers. This is geared toward programmers that are very new to javascript and covers some basics, but focuses on Functions, Objects and prototypal inheritance ideas.

javascript beginner
Prototype-oriented programming
Inheritance: level 2
Car.startEngine = function() {
  Vehicle.startEngine.call(this); // ≃ super.start
  console.log("model: " + this.model);
}

// inheritance is not limited to one level
var myPigeot = Object.create(Car);
myPigeot.description = "My Pigeot";
myPigeot.model = "403";

myPigeot.startEngine();
// My Pigeot: engine started
// model: 403
Prototype-oriented programming
Classes in JS?

    Vehicule
                           Car



                              myPigeot


Vehicle, Car = prototypes ≃ classes
Note: myPigeot can be prototype too!
Prototype-oriented programming




             Wait!...

   What about that Object.create()?
Prototype-oriented programming
Create an instance
// Object.create(): JS 1.8.5 and +
if (!Object.create) {
   Object.create = function(o) {
      // creates new temp. constructor
      function F() {}

         // gives it o as prototype
         F.prototype = o;

         // instantiates
         return new F();
    };
}

Recommended for you

AngularJS with TypeScript and Windows Azure Mobile Services
AngularJS with TypeScript and Windows Azure Mobile ServicesAngularJS with TypeScript and Windows Azure Mobile Services
AngularJS with TypeScript and Windows Azure Mobile Services

In the coming two weeks I will do a series of talks at various conferences in Austria and Germany. I will speak about AngularJS, TypeScript, and Windows Azure Mobile Services. In this blog post I publish the slides and the sample code.

angularjssoftware developmentmvc
Protocol in Swift
Protocol in SwiftProtocol in Swift
Protocol in Swift

This document discusses protocols in Swift. It defines a protocol as a blueprint of methods, properties, and requirements that can be adopted by classes, structures, and enumerations. Protocols like Equatable, Comparable, and CollectionType are built-in to Swift and provide common functionality. The document provides examples of built-in protocols and how protocol extensions allow adding functionality to existing protocols.

Information Security Lesson 7 - Remote Access - Eric Vanderburg
Information Security Lesson 7 - Remote Access - Eric VanderburgInformation Security Lesson 7 - Remote Access - Eric Vanderburg
Information Security Lesson 7 - Remote Access - Eric Vanderburg

This document discusses various methods for remote access and securing communications, including FTP, tunneling protocols like PPTP and L2TP, SSH, and IPSec. It also covers wireless technologies like 802.11 standards, cellular networks, and authentication methods such as RADIUS, EAP, and 802.1x. Throughout it provides details on configuration and implementation of these various remote access and security protocols.

information securityeric vanderburgremote access
Prototype-oriented programming
Classes in JS
// previous example could have been written:
var Vehicle = { /* desc, startEngine */ };

function Car(desc) { this.description = desc; }

Car.prototype = Vehicle;

Car.prototype.description = "some car";
Car.prototype.wheelCount = 4;

var myPigeot = new Car("My Pigeot");
myPigeot.model = "403";
Prototype-oriented programming
New in JS
    Er... Car is a functions, but I can new it?!

● new is a keyword that
  1. Allocates an object
  2. Inits this object with constructor


●   new Car("some car") is equivalent to
      var car = {};
      car.__proto__ = Car.prototype;
      Car.call(car, "some car");
Prototype-oriented programming
Last word about constructor functions
What happens when calling the Car
constructor without new?

       this is bound to global object

Want to play this game?
  ○ Change window.location and you'll risk a crash
Prototype-oriented programming
Last but not least
● Be carefull with this and new

● Factory method instead of new
  function createCar(d) { return new Car(d); }

● Prevent bad usage of your constructor
  function Car(desc) {
     if (!(this instanceof Car)) {
        return new Car(desc);
     }
     /* ... */
  }

Recommended for you

Adobe and Modern Web Development
Adobe and Modern Web DevelopmentAdobe and Modern Web Development
Adobe and Modern Web Development

This document discusses modern web development and Adobe's role. It introduces Adobe's developer evangelist and their focus on the future of the web. Key technologies mentioned include Creative Cloud, Dreamweaver, PhoneGap Build, Brackets, Shadow, and Create.js. The document demonstrates new capabilities in areas like CSS contributions and concludes by inviting the audience to follow up for more information.

Personal Security Expo
Personal Security ExpoPersonal Security Expo
Personal Security Expo

This document provides tips for personal safety and security. It discusses what security and personal safety mean and emphasizes prevention over reaction or luck. It gives advice for walking on streets, in parking lots, driving, and what to do if attacked. The key tips are to remain calm, avoid confrontation, and prioritize survival in dangerous situations. Prevention through awareness of one's environment is stressed as the most important factor for ensuring personal security.

Beyond the Standards
Beyond the StandardsBeyond the Standards
Beyond the Standards

Forget about Web standards and go way beyond the usual capabilities of Web scripting languages. Learn how to create stunning effects using canvas/svg/vml, how to control animated graphics in JavaScript, and how to merge all kinds of standards and technologies to create a whole new world of possibilities. Using Paul\'s latest project as an example, he shows you how to adapt the things he talks about into new projects, featuring his new JavaScript game engine. Paul demonstrates how to control animated graphics in the browser, how to scale and rotate elements smoothly, and how to combine canvas, svg and filters with CSS to adapt new standards in browsers that don\'t support them. See how to move physics from the real world to the Web browser.

javascriptjqueryexperience
Prototype-oriented programming
Private members
var Entity = (function() { // class lvl
   var counter = 0;        // private

  return function() {      // instance lvl
    var id = counter++;    // private

     this.getId = function() {
       return id;
     }
   };
})();
Prototype-oriented programming
Private members
var o1 = new Entity();
var o2 = new Entity();

console.log(o1.id);
> undefined

console.log(o1.getId());
> 1

console.log(o2.getId());
> 2
Access to Your Web Page
DOM manipulation
DOM != JS, it's another API

No need for jQuery
  ○   getElementById()
  ○   getElementByTagName()
  ○   getElementByName()
  ○   getElementByClassName()   // !IE
  ○   querySelector()             // IE 8
  ○   querySelectorAll()        // IE 8
Access to Your Web Page
DOM manipulation: tips

● know your CSS selectors
  ○ #element
  ○ .element
  ○ [attribute=value]


● limit changes to the DOM
  ○ use fragments

Recommended for you

Jquery
JqueryJquery
Jquery

This document provides an overview of jQuery including: - Main jQuery objects like DOM tree, window, and document - How to select elements using jQuery selectors - How to get and set attributes, CSS, HTML and text of elements - How to handle events like click and toggle using jQuery - How to animate elements by showing, hiding, and changing styles - Common jQuery plugins and tools for debugging - Links to documentation and learning resources for jQuery

folzayhassan
JavaScript & Animation
JavaScript & AnimationJavaScript & Animation
JavaScript & Animation

The document discusses different techniques for animating with JavaScript, including setTimeout, jQuery animate, CSS animations with @keyframes, and CreateJS. It provides links to examples and resources for animating with each technique. While CSS animations and CreateJS are better than the basic alternatives, they are still not fully easy to use. The document concludes by mentioning the combination of Socket.io and CreateJS for real-time collaborative coding applications.

Designing The Mobile User Experience
Designing The Mobile User ExperienceDesigning The Mobile User Experience
Designing The Mobile User Experience

The document discusses the history and evolution of mobile devices and user interfaces. It covers topics like screen sizes, input methods, browsers, and design best practices. The mobile experience has progressed from basic phones and screens to touch interfaces, sensors and personalized experiences. Good mobile design requires understanding context, usability testing on actual devices, and adapting to ongoing technological changes.

mobiledesignuser
The Good, The Bad, and The Ugly
References
Books
David Flanagan, JavaScript: The Definitive Guide, 6th
Edition, O'Reilly Media, April 2011

Doug Crockford, JavaScript: The Good Parts, O'Reilly
Media, May 2008
References
Online
Doug Crockford, JavaScript: The Good Parts
http://googlecode.blogspot.com/2009/03/doug-crockford-
javascript-good-parts.html

Alex Russel, Learning to Love JavaScript
http://www.google.com/events/io/2011/sessions/learning-to-
love-javascript.html

John Resig, Learning Advanced JavaScript
http://ejohn.org/apps/learn/

Mozilla, JavaScript Reference
https://developer.mozilla.org/en/JavaScript/Reference/

More Related Content

What's hot

JavaScript Functions
JavaScript FunctionsJavaScript Functions
JavaScript Functions
Colin DeCarlo
 
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptWorkshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScript
Visual Engineering
 
Day 1
Day 1Day 1
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
Jussi Pohjolainen
 
Javascript basics for automation testing
Javascript  basics for automation testingJavascript  basics for automation testing
Javascript basics for automation testing
Vikas Thange
 
Oojs 1.1
Oojs 1.1Oojs 1.1
Oojs 1.1
Rodica Dada
 
Journey of a C# developer into Javascript
Journey of a C# developer into JavascriptJourney of a C# developer into Javascript
Journey of a C# developer into Javascript
Massimo Franciosa
 
Reactive, component 그리고 angular2
Reactive, component 그리고  angular2Reactive, component 그리고  angular2
Reactive, component 그리고 angular2
Jeado Ko
 
Powerful JavaScript Tips and Best Practices
Powerful JavaScript Tips and Best PracticesPowerful JavaScript Tips and Best Practices
Powerful JavaScript Tips and Best Practices
Dragos Ionita
 
A Deeper look into Javascript Basics
A Deeper look into Javascript BasicsA Deeper look into Javascript Basics
A Deeper look into Javascript Basics
Mindfire Solutions
 
Things about Functional JavaScript
Things about Functional JavaScriptThings about Functional JavaScript
Things about Functional JavaScript
ChengHui Weng
 
Intro to Javascript
Intro to JavascriptIntro to Javascript
Intro to Javascript
Anjan Banda
 
Protocol-Oriented Programming in Swift
Protocol-Oriented Programming in SwiftProtocol-Oriented Programming in Swift
Protocol-Oriented Programming in Swift
Oleksandr Stepanov
 
Beginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScriptBeginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScript
Stoyan Stefanov
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
Mats Bryntse
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
Bala Narayanan
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
Fu Cheng
 
Javascript tid-bits
Javascript tid-bitsJavascript tid-bits
Javascript tid-bits
David Atchley
 
AngularJS with TypeScript and Windows Azure Mobile Services
AngularJS with TypeScript and Windows Azure Mobile ServicesAngularJS with TypeScript and Windows Azure Mobile Services
AngularJS with TypeScript and Windows Azure Mobile Services
Rainer Stropek
 
Protocol in Swift
Protocol in SwiftProtocol in Swift
Protocol in Swift
Yusuke Kita
 

What's hot (20)

JavaScript Functions
JavaScript FunctionsJavaScript Functions
JavaScript Functions
 
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptWorkshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScript
 
Day 1
Day 1Day 1
Day 1
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
 
Javascript basics for automation testing
Javascript  basics for automation testingJavascript  basics for automation testing
Javascript basics for automation testing
 
Oojs 1.1
Oojs 1.1Oojs 1.1
Oojs 1.1
 
Journey of a C# developer into Javascript
Journey of a C# developer into JavascriptJourney of a C# developer into Javascript
Journey of a C# developer into Javascript
 
Reactive, component 그리고 angular2
Reactive, component 그리고  angular2Reactive, component 그리고  angular2
Reactive, component 그리고 angular2
 
Powerful JavaScript Tips and Best Practices
Powerful JavaScript Tips and Best PracticesPowerful JavaScript Tips and Best Practices
Powerful JavaScript Tips and Best Practices
 
A Deeper look into Javascript Basics
A Deeper look into Javascript BasicsA Deeper look into Javascript Basics
A Deeper look into Javascript Basics
 
Things about Functional JavaScript
Things about Functional JavaScriptThings about Functional JavaScript
Things about Functional JavaScript
 
Intro to Javascript
Intro to JavascriptIntro to Javascript
Intro to Javascript
 
Protocol-Oriented Programming in Swift
Protocol-Oriented Programming in SwiftProtocol-Oriented Programming in Swift
Protocol-Oriented Programming in Swift
 
Beginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScriptBeginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScript
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
Javascript tid-bits
Javascript tid-bitsJavascript tid-bits
Javascript tid-bits
 
AngularJS with TypeScript and Windows Azure Mobile Services
AngularJS with TypeScript and Windows Azure Mobile ServicesAngularJS with TypeScript and Windows Azure Mobile Services
AngularJS with TypeScript and Windows Azure Mobile Services
 
Protocol in Swift
Protocol in SwiftProtocol in Swift
Protocol in Swift
 

Viewers also liked

Information Security Lesson 7 - Remote Access - Eric Vanderburg
Information Security Lesson 7 - Remote Access - Eric VanderburgInformation Security Lesson 7 - Remote Access - Eric Vanderburg
Information Security Lesson 7 - Remote Access - Eric Vanderburg
Eric Vanderburg
 
Adobe and Modern Web Development
Adobe and Modern Web DevelopmentAdobe and Modern Web Development
Adobe and Modern Web Development
Terry Ryan
 
Personal Security Expo
Personal Security ExpoPersonal Security Expo
Personal Security Expo
jdspider
 
Beyond the Standards
Beyond the StandardsBeyond the Standards
Beyond the Standards
Paul Bakaus
 
Jquery
JqueryJquery
JavaScript & Animation
JavaScript & AnimationJavaScript & Animation
JavaScript & Animation
Caesar Chi
 
Designing The Mobile User Experience
Designing The Mobile User ExperienceDesigning The Mobile User Experience
Designing The Mobile User Experience
Jose Alves
 
Java Script Animation
Java Script AnimationJava Script Animation
Java Script Animation
rbiggs
 
Javascript Animation with Canvas - Gregory Starr 2015
Javascript Animation with Canvas - Gregory Starr 2015Javascript Animation with Canvas - Gregory Starr 2015
Javascript Animation with Canvas - Gregory Starr 2015
Gregory Starr
 
JavaScript Libraries: The Big Picture
JavaScript Libraries: The Big PictureJavaScript Libraries: The Big Picture
JavaScript Libraries: The Big Picture
Simon Willison
 
Introuction To jQuery
Introuction To jQueryIntrouction To jQuery
Introuction To jQuery
Winster Lee
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
Marc Grabanski
 

Viewers also liked (12)

Information Security Lesson 7 - Remote Access - Eric Vanderburg
Information Security Lesson 7 - Remote Access - Eric VanderburgInformation Security Lesson 7 - Remote Access - Eric Vanderburg
Information Security Lesson 7 - Remote Access - Eric Vanderburg
 
Adobe and Modern Web Development
Adobe and Modern Web DevelopmentAdobe and Modern Web Development
Adobe and Modern Web Development
 
Personal Security Expo
Personal Security ExpoPersonal Security Expo
Personal Security Expo
 
Beyond the Standards
Beyond the StandardsBeyond the Standards
Beyond the Standards
 
Jquery
JqueryJquery
Jquery
 
JavaScript & Animation
JavaScript & AnimationJavaScript & Animation
JavaScript & Animation
 
Designing The Mobile User Experience
Designing The Mobile User ExperienceDesigning The Mobile User Experience
Designing The Mobile User Experience
 
Java Script Animation
Java Script AnimationJava Script Animation
Java Script Animation
 
Javascript Animation with Canvas - Gregory Starr 2015
Javascript Animation with Canvas - Gregory Starr 2015Javascript Animation with Canvas - Gregory Starr 2015
Javascript Animation with Canvas - Gregory Starr 2015
 
JavaScript Libraries: The Big Picture
JavaScript Libraries: The Big PictureJavaScript Libraries: The Big Picture
JavaScript Libraries: The Big Picture
 
Introuction To jQuery
Introuction To jQueryIntrouction To jQuery
Introuction To jQuery
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 

Similar to JavaScript Core

Java script for web developer
Java script for web developerJava script for web developer
Java script for web developer
Chalermpon Areepong
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
David Padbury
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
David Padbury
 
The Beauty of Java Script
The Beauty of Java ScriptThe Beauty of Java Script
The Beauty of Java Script
Michael Girouard
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5a
rajivmordani
 
JavaScript and UI Architecture Best Practices
JavaScript and UI Architecture Best PracticesJavaScript and UI Architecture Best Practices
JavaScript and UI Architecture Best Practices
Siarhei Barysiuk
 
JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)
Piyush Katariya
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
Zohar Arad
 
Future of Web Apps: Google Gears
Future of Web Apps: Google GearsFuture of Web Apps: Google Gears
Future of Web Apps: Google Gears
dion
 
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
pjcozzi
 
JavaScript ES6
JavaScript ES6JavaScript ES6
JavaScript ES6
Leo Hernandez
 
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
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
Amit Tyagi
 
How AngularJS Embraced Traditional Design Patterns
How AngularJS Embraced Traditional Design PatternsHow AngularJS Embraced Traditional Design Patterns
How AngularJS Embraced Traditional Design Patterns
Ran Mizrahi
 
ES6: The Awesome Parts
ES6: The Awesome PartsES6: The Awesome Parts
ES6: The Awesome Parts
Domenic Denicola
 
Cappuccino @ JSConf 2009
Cappuccino @ JSConf 2009Cappuccino @ JSConf 2009
Cappuccino @ JSConf 2009
tolmasky
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Libraries
jeresig
 
Design Summit - UI Roadmap - Dan Clarizio, Martin Povolny
Design Summit - UI Roadmap - Dan Clarizio, Martin PovolnyDesign Summit - UI Roadmap - Dan Clarizio, Martin Povolny
Design Summit - UI Roadmap - Dan Clarizio, Martin Povolny
ManageIQ
 
Front End Development: The Important Parts
Front End Development: The Important PartsFront End Development: The Important Parts
Front End Development: The Important Parts
Sergey Bolshchikov
 
Wakanday JS201 Best Practices
Wakanday JS201 Best PracticesWakanday JS201 Best Practices
Wakanday JS201 Best Practices
Juergen Fesslmeier
 

Similar to JavaScript Core (20)

Java script for web developer
Java script for web developerJava script for web developer
Java script for web developer
 
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
 
The Beauty of Java Script
The Beauty of Java ScriptThe Beauty of Java Script
The Beauty of Java Script
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5a
 
JavaScript and UI Architecture Best Practices
JavaScript and UI Architecture Best PracticesJavaScript and UI Architecture Best Practices
JavaScript and UI Architecture Best Practices
 
JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
Future of Web Apps: Google Gears
Future of Web Apps: Google GearsFuture of Web Apps: Google Gears
Future of Web Apps: Google Gears
 
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
 
JavaScript ES6
JavaScript ES6JavaScript ES6
JavaScript ES6
 
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...
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
How AngularJS Embraced Traditional Design Patterns
How AngularJS Embraced Traditional Design PatternsHow AngularJS Embraced Traditional Design Patterns
How AngularJS Embraced Traditional Design Patterns
 
ES6: The Awesome Parts
ES6: The Awesome PartsES6: The Awesome Parts
ES6: The Awesome Parts
 
Cappuccino @ JSConf 2009
Cappuccino @ JSConf 2009Cappuccino @ JSConf 2009
Cappuccino @ JSConf 2009
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Libraries
 
Design Summit - UI Roadmap - Dan Clarizio, Martin Povolny
Design Summit - UI Roadmap - Dan Clarizio, Martin PovolnyDesign Summit - UI Roadmap - Dan Clarizio, Martin Povolny
Design Summit - UI Roadmap - Dan Clarizio, Martin Povolny
 
Front End Development: The Important Parts
Front End Development: The Important PartsFront End Development: The Important Parts
Front End Development: The Important Parts
 
Wakanday JS201 Best Practices
Wakanday JS201 Best PracticesWakanday JS201 Best Practices
Wakanday JS201 Best Practices
 

More from François Sarradin

Java (8) eXperiments - DevoxxFR 2016
Java (8) eXperiments - DevoxxFR 2016Java (8) eXperiments - DevoxxFR 2016
Java (8) eXperiments - DevoxxFR 2016
François Sarradin
 
Java8 eXperiment - Normandy JUG
Java8 eXperiment - Normandy JUGJava8 eXperiment - Normandy JUG
Java8 eXperiment - Normandy JUG
François Sarradin
 
FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)
FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)
FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)
François Sarradin
 
Scala vs java 8
Scala vs java 8Scala vs java 8
Scala vs java 8
François Sarradin
 
Java 8 Lambda
Java 8 LambdaJava 8 Lambda
Java 8 Lambda
François Sarradin
 

More from François Sarradin (6)

Java (8) eXperiments - DevoxxFR 2016
Java (8) eXperiments - DevoxxFR 2016Java (8) eXperiments - DevoxxFR 2016
Java (8) eXperiments - DevoxxFR 2016
 
Java8 eXperiment - Normandy JUG
Java8 eXperiment - Normandy JUGJava8 eXperiment - Normandy JUG
Java8 eXperiment - Normandy JUG
 
FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)
FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)
FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)
 
Scala vs java 8
Scala vs java 8Scala vs java 8
Scala vs java 8
 
Java 8 Lambda
Java 8 LambdaJava 8 Lambda
Java 8 Lambda
 
Programmation Fonctionnelle
Programmation FonctionnelleProgrammation Fonctionnelle
Programmation Fonctionnelle
 

JavaScript Core

  • 1. JavaScript Core Nicolas Demengel and François Sarradin
  • 2. Application (client side) Web Page Animation HTLM(5) CSS(3) Client JavaScript Server JS Engine Service (server side) Embeded (noSql, ...)
  • 3. JavaScript History 1996 1998 1995 1997 2000 2010 What's next? ECMA 1.3 1.0, 1.1 1.5 1.8.5 ES 6 ES 3 ES 5 Harmony ECMAScript Brendan Eich 1.2 @ Netscape JavaScript
  • 4. JavaScript Is made of... Self Python Perl C/Java JavaScript ActionScript Dart CoffeeScript
  • 5. JavaScript Language & Concepts
  • 6. JavaScript Syntax Looks like Java / C++ /* Factorial of n. */ function fact(n) { // result of fact var result = 1; for (var i = 1; i <= n; i++) { result *= i; } return result; }
  • 7. JavaScript Is dynamically typed var x = 1; // it should be an int var s = "a"; // string or char? // it's a function, (type of p? // does it return something?) function f(p) { /* ... */ } var g; // anything (even a function)
  • 8. JavaScript Has bad parts 42 == '42' !== 42 if (false) <-> if (null) <-> if (undefined) false != null == undefined false !== null !== undefined return { prop: "val" }; Use an editor providing validation with JSLint
  • 9. JavaScript Has few built-in types ● Boolean true / false ● Number 42 21.6 NaN +∞ -∞ ● String "hi" 'hello' ● Date java-like ● Regexp /^.*([0-9]+)w{2,3}$/ ● Object {prop: val} ● Array [a, b] (it's just an Object) ● Function function() {} ● List, Map, Set: where are you? => ES 6
  • 10. JavaScript Can define functions // function declaration (statement) function f(x) { /* ... */ } // function expression (operator) var f = function(x) { /* ... */ }; // Function constructor var f = new Function('x', '...');
  • 11. JavaScript CAN HAZ FUNCTIONZ EVERYWHERE function compose(f, g) { // BTW, this is a closure! // more on that later return function(x) { return f(g(x)); }; } compose(square, add_one)(10);
  • 12. JavaScript Function: scope & binding var o = { name: "an object", logName: function() { log(this.name); } }; // o.logName can be assigned to a variable: var logN = o.logName; logN(); // another way to give o the logName method function ln() { log(this.name); } var o = { name: "an object" }; o.logName = ln;
  • 13. JavaScript Function: scope & binding // what is the value of 'this'? var o = { /* ... */ logName: function() { log(this.name); } }; // here it obviously refers to o o.logName(); // what about the following? function ln() { log(this.name); } ln(); // er...
  • 14. JavaScript Function: scope & binding ● this = object to wich the function is bound ○ By default: the global object (window in browsers) ● Change the way a function is bound to an object: apply or call
  • 15. JavaScript Function: scope & binding var o = { nm: "John Doe" }; function say(message) { console.log(this.nm + ": " + message); } say("hello!"); // ": hello!" (this.nm is undefined) o.sayIt = say; o.sayIt("greetings!"); // "John Doe: greetings!" say.call(o, "yo!"); // "John Doe: yo!" say.apply(o, ["hi!"]); // "John Doe: hi!"
  • 16. JavaScript Function arguments (function(x, y) { console.log(y); > 'b' console.log(arguments.length); > 3 console.log(arguments[2]); > 'c' console.log(arguments.callee);> function(){ } console.log(arguments.join); > undefined // Array.prototype.join.call(arguments) })('a', 'b', 'c');
  • 17. Prototype-oriented programming Languages Self NewtonScript JavaScript Lua Io Ioke JVM
  • 18. Prototype-oriented programming Instance, prototype, and inheritance var Vehicle = { description: "some vehicle", startEngine: function() { console.log(this.description + " => engine started"); } }; // uses Vehicle as proto var Car = Object.create(Vehicle); Car.description = "some car"; Car.wheelCount = 4;
  • 19. Prototype-oriented programming What do you get? Vehicle.startEngine(); > "some vehicle => engine started" Car.startEngine(); > "some car => engine started" console.log(Vehicle.wheelCount); > undefined console.log(Car.wheelCount); > 4
  • 20. Prototype-oriented programming Inheritance manipulation Car.startEngine = function() { console.log("overridden"); } Car.startEngine(); > "overridden" // let's delete the car-specific method delete Car.startEngine; // parent method is still there Car.startEngine(); > "some car => engine started" JS prototype-based programming = delegation (object ⇒ prototype)
  • 21. Prototype-oriented programming Inheritance: level 2 Car.startEngine = function() { Vehicle.startEngine.call(this); // ≃ super.start console.log("model: " + this.model); } // inheritance is not limited to one level var myPigeot = Object.create(Car); myPigeot.description = "My Pigeot"; myPigeot.model = "403"; myPigeot.startEngine(); // My Pigeot: engine started // model: 403
  • 22. Prototype-oriented programming Classes in JS? Vehicule Car myPigeot Vehicle, Car = prototypes ≃ classes Note: myPigeot can be prototype too!
  • 23. Prototype-oriented programming Wait!... What about that Object.create()?
  • 24. Prototype-oriented programming Create an instance // Object.create(): JS 1.8.5 and + if (!Object.create) { Object.create = function(o) { // creates new temp. constructor function F() {} // gives it o as prototype F.prototype = o; // instantiates return new F(); }; }
  • 25. Prototype-oriented programming Classes in JS // previous example could have been written: var Vehicle = { /* desc, startEngine */ }; function Car(desc) { this.description = desc; } Car.prototype = Vehicle; Car.prototype.description = "some car"; Car.prototype.wheelCount = 4; var myPigeot = new Car("My Pigeot"); myPigeot.model = "403";
  • 26. Prototype-oriented programming New in JS Er... Car is a functions, but I can new it?! ● new is a keyword that 1. Allocates an object 2. Inits this object with constructor ● new Car("some car") is equivalent to var car = {}; car.__proto__ = Car.prototype; Car.call(car, "some car");
  • 27. Prototype-oriented programming Last word about constructor functions What happens when calling the Car constructor without new? this is bound to global object Want to play this game? ○ Change window.location and you'll risk a crash
  • 28. Prototype-oriented programming Last but not least ● Be carefull with this and new ● Factory method instead of new function createCar(d) { return new Car(d); } ● Prevent bad usage of your constructor function Car(desc) { if (!(this instanceof Car)) { return new Car(desc); } /* ... */ }
  • 29. Prototype-oriented programming Private members var Entity = (function() { // class lvl var counter = 0; // private return function() { // instance lvl var id = counter++; // private this.getId = function() { return id; } }; })();
  • 30. Prototype-oriented programming Private members var o1 = new Entity(); var o2 = new Entity(); console.log(o1.id); > undefined console.log(o1.getId()); > 1 console.log(o2.getId()); > 2
  • 31. Access to Your Web Page DOM manipulation DOM != JS, it's another API No need for jQuery ○ getElementById() ○ getElementByTagName() ○ getElementByName() ○ getElementByClassName() // !IE ○ querySelector() // IE 8 ○ querySelectorAll() // IE 8
  • 32. Access to Your Web Page DOM manipulation: tips ● know your CSS selectors ○ #element ○ .element ○ [attribute=value] ● limit changes to the DOM ○ use fragments
  • 33. The Good, The Bad, and The Ugly
  • 34. References Books David Flanagan, JavaScript: The Definitive Guide, 6th Edition, O'Reilly Media, April 2011 Doug Crockford, JavaScript: The Good Parts, O'Reilly Media, May 2008
  • 35. References Online Doug Crockford, JavaScript: The Good Parts http://googlecode.blogspot.com/2009/03/doug-crockford- javascript-good-parts.html Alex Russel, Learning to Love JavaScript http://www.google.com/events/io/2011/sessions/learning-to- love-javascript.html John Resig, Learning Advanced JavaScript http://ejohn.org/apps/learn/ Mozilla, JavaScript Reference https://developer.mozilla.org/en/JavaScript/Reference/