JavaScript provides core functionality for web pages and applications. It has a C-like syntax and is dynamically typed. JavaScript code runs on both the client-side in web browsers and the server-side in environments like Node.js. It uses prototype-based inheritance where objects can inherit properties from object prototypes. New features are being added regularly through the ECMAScript specification. JavaScript allows DOM manipulation to modify web pages and event handling for user interactions.
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.
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.
In JS: CLASS <=> Constructor FN
new FN() => FN() { this }
FN = CLASS (FN = FN, FN = DATA)
Objects
Prototype / __proto__
Inheritence
Rewriting / Augmenting
built in objects
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)
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.
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.
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.
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.
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.
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.
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 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.
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.
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.
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.
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
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.
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.
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.
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.
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
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.
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.
Functions being first-class citizens in JavaScript offers developers a tremendous amount power and
flexibilty. However, what good is all this power if you don't know how to harness it?
This talk will provide a thorough examination of JavaScript functions. Topics
that will be covered in this talk are:
* Functions are objects
* Execution Context and the Scope Chain
* Closures
* Modifying Context
* The Various Forms of Functions.
Attendees will leave this talk understanding the power of JavaScript functions and the knowledge to apply new
techiques that will make their JavaScript cleaner, leaner and more maintainable.
This document provides an overview and introduction to building a basic fraction calculator app in Objective-C. It begins with an overview of the project architecture using the MVC pattern with a Fraction model class to represent fractions, a Calculator class to perform operations, and a ViewController class to manage the user interface. It then details the implementation of each class, including the Fraction class with methods for creating, modifying, and performing operations on fractions, the Calculator class for setting operands and performing operations, and the ViewController class for handling user interface events and updating the display.
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 testingVikas Thange
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.
In JS: CLASS <=> Constructor FN
new FN() => FN() { this }
FN = CLASS (FN = FN, FN = DATA)
Objects
Prototype / __proto__
Inheritence
Rewriting / Augmenting
built in objects
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)
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.
Powerful JavaScript Tips and Best PracticesDragos Ionita
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.
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.
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.
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.
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.
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 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.
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.
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.
AngularJS with TypeScript and Windows Azure Mobile ServicesRainer Stropek
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.
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 VanderburgEric 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.
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.
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.
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.
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
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.
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.
This was my presentation on JavaScript Animation for Silicon Valley Code Camp 09. You get the material from http://my/personal/rbiggs/Blog/default.aspx
This document provides an overview of popular JavaScript libraries including Dojo Toolkit, YUI, Prototype, and jQuery. It discusses problems they aim to solve like cross-browser inconsistencies. Key features of each library are mentioned like Dojo's widgets, YUI's controls, Prototype's Ruby-like syntax, and jQuery's chaining and node selection. The document also covers ideas from the libraries like progressive enhancement, animation APIs, and leveraging hosting on CDNs.
This document discusses jQuery, a JavaScript library for DOM manipulation, events, effects and Ajax interactions for rapid web development. It covers jQuery's core features like DOM selection and manipulation, events, effects and animations. It also discusses related topics like the Document Object Model, CSS selectors, traversing the DOM, asynchronous requests and common plugins.
The document discusses jQuery and its uses and methods. It introduces jQuery as a way to write JavaScript code that works across browsers. It provides examples of how jQuery can be used to select and manipulate HTML elements using simpler syntax compared to vanilla JavaScript. Key jQuery methods are also summarized, including how to select elements, modify attributes, handle events, add/move elements, and perform animations and AJAX requests.
The document provides an introduction to developing complex front-end applications using HTML and JavaScript. It discusses how JavaScript modules can be organized in a way that is similar to frameworks like WPF and Silverlight using simple constructs like the module pattern. It also covers asynchronous module definition (AMD) and how modules can be loaded and dependencies managed using RequireJS. The document demonstrates unit testing jQuery code and using pubsub for loose coupling between modules. Finally, it discusses how CSS compilers like SASS can make CSS authoring more productive by allowing variables, nesting and mixins.
JavaScript is evolving with the addition of modules, platform consistency, and harmony features. Modules allow JavaScript code to be organized and avoid naming collisions. CommonJS and AMD module formats are used widely. Platform consistency is improved through polyfills that mimic future APIs for older browsers. Harmony brings language-level modules and features like destructuring assignment, default parameters, and promises to JavaScript. Traceur compiles Harmony code to existing JavaScript.
The document discusses the beauty of JavaScript and its many features. It covers how JavaScript offers classless object-oriented programming and functional programming. It also discusses how JavaScript can run on both the client-side and server-side. The document provides examples of JavaScript syntax like variables, functions, objects, prototypes and more to demonstrate JavaScript's capabilities. It emphasizes that libraries help create abstractions and beautiful patterns in JavaScript code.
The document discusses the beauty of JavaScript and its many features. It covers how JavaScript offers classless object-oriented programming and functional programming. It also discusses how JavaScript can run on both the client-side and server-side. The document provides examples of JavaScript syntax like variables, functions, objects, inheritance through prototypes, and AJAX requests. It emphasizes how libraries help create abstractions and beautiful patterns in JavaScript code.
MyApp provides JavaScript best practices including:
1) Using namespaces to avoid naming collisions and define packages like MyApp.string.utils for reusable functions.
2) Branching code during initialization or lazily on first use to handle browser differences efficiently.
3) Passing configuration as an object instead of many parameters to simplify function calls.
4) Defining private methods and properties using closures to encapsulate code.
5) Employing self-executing functions for one-time initialization tasks.
6) Allowing method chaining for readability when calling several related methods.
This document provides an overview of the history and evolution of JavaScript. It discusses key dates and specifications including its first appearance in 1995 in Netscape Navigator 2.0 and the standardization process in the late 1990s. The document also covers JavaScript's core features like being dynamic, single-threaded, asynchronous and event-driven. It describes JavaScript's data types, objects, functions and common array methods. Overall, the document presents a comprehensive introduction to JavaScript from its origins to modern usage.
This document discusses several JavaScript design patterns including singleton, module, engine, event-driven programming, and templates. It provides code examples and explanations for each pattern. The patterns are introduced as ways to make programming easier by improving code organization, reuse, separation of concerns, and error handling.
This document discusses ES6, the new version of JavaScript, and provides an overview of some of its key features including classes, iterators, lambdas, string interpolation, modules, and let block scoping. It encourages readers to begin using ES6 today by leveraging transpilation tools like Babel that allow ES6 code to run on current browsers and platforms. The best resource mentioned for learning ES6 is the Babel website, which contains tutorials, a live code editor, and helps developers get started with ES6.
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...GITS Indonesia
Salah satu front-end developer GITS Indonesia, Warsono, mengisi workshop di universitas, mengenai Vue.js.
Ikuti kami di kanal berikut, agar tidak ketinggalan acara seru:
Instagram: @gitsindonesia
LinkedIn: GITS Indonesia
Website: gits.id
The next version of JavaScript, ES6, is starting to arrive. Many of its features are simple enhancements to the language we already have: things like arrow functions, class syntax, and destructuring. But other features will change the way we program JavaScript, fundamentally expanding the capabilities of the language and reshaping our future codebases. In this talk we'll focus on two of these, discovering the the myriad possibilities of generators and the many tricks you can pull of with template strings.
The document discusses Objective-J, a JavaScript implementation that adds features from other languages like Ruby and Python. It highlights features like classical inheritance, dynamic dispatch, and method missing. It also discusses debugging tools for JavaScript like profile views. Finally, it provides links to learn more about Cappuccino and Objective-J.
The document discusses secrets and techniques for JavaScript libraries. It covers topics like the JavaScript language, cross-browser code, events, DOM traversal, styles, animations, distribution, and HTML insertion. It provides examples and explanations of techniques for class creation, timers, options, subclassing, custom events, selector internals, computed styles, and dimension calculations.
Design Summit - UI Roadmap - Dan Clarizio, Martin PovolnyManageIQ
The UI, while fullty-features, is intimidating to new users. The roadmap for the UI is to make it more intuitive and navigable for new users.
For more on ManageIQ, see http://manageiq.org/
The important parts of the front end development sphere including CSS3, advanced JavaScript, libraries such as jQuery, RequireJS and Promises. And finally, chrome developer tools for successful debugging and editing.
This document discusses JavaScript best practices for naming variables and functions, code formatting and style, scopes and closures, and class-like structures. It provides examples of how to use descriptive names, consistent formatting, closures to manage variable scopes, immediately invoked function expressions (IIFEs), and dataclass structures in Wakanda to define classes. Following these practices can improve code readability, maintainability and reduce bugs.
Dans cette présentation, je vous propose de découvrir ensemble d’autre façon de développer en Java et Java 8 en particulier, mais que peu ont testé. Est-il possible de limiter le nombre de sous-classes pour une classe ? Si on peut désormais mettre un comportement dans une interface, peut-on y mettre un état ? Et peut-on sécuriser la grammaire de ses DSL internes ? Live coding à l’appui, voici certaines des questions auxquelles nous allons essayer de répondre ou qu’on ne devrait jamais aborder.
Dans cette présentation, je vous propose de découvrir ensemble ce qu’il est vraiment possible d’exprimer avec Java 8 et que peu ont testé. Est-il possible de limiter le nombre de sous-classes pour une classe ? Si on peut désormais mettre un comportement dans une interface, peut-on y mettre un état ? Live coding à l’appui, voici certaines des questions auxquelles nous allons essayer de répondre ou qu’on ne devrait jamais aborder.
Code : https://gist.github.com/fsarradin/bea95af73651a57c1112
FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)François Sarradin
This document summarizes a presentation on monads explained to programmers. It discusses using monads like Try and Future in Scala to handle exceptions and asynchronous code in a functional way. It also discusses how monads allow separating technical concerns from business logic through composition. The presentation code examples demonstrate using for-comprehensions and flatMap with Try and Future to handle failures and combine asynchronous results in a declarative way.
This document provides an overview and comparison of new features in Java 8 and Scala, with a focus on lambda expressions. It notes that Java 8 adds lambda expressions and default interface methods to provide more expressiveness and concurrency capabilities similar to functional programming languages like Scala. The document discusses how lambda expressions improve on anonymous inner classes in Java and demonstrates various lambda expression forms in both Java 8 and Scala. It also highlights new Java 8 features like method references and parallel streams for easier parallel programming.
Here are a few thoughts in response to your questions:
- Lambda expressions will significantly improve readability and reduce noise in Java code by allowing for more concise one-liners compared to anonymous inner classes. However, debugging lambdas could potentially be more challenging since they are anonymous by nature. Tools and IDE support will need to evolve to help with this.
- With features like lambdas and default methods, Java 8 aims to become more competitive with languages like C# and Scala that already have closures and functional capabilities. However, Java's large existing code base and ecosystem give it advantages over newer languages.
- For Java 8 to be widely adopted, projects should start evaluating and migrating to it as early access
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
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;
}
};
})();
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
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/