Why
javascript ROCKS
(And why you should be using it)
Lingua Franca of the Web
When JavaScript was first introduced, I dismissed it as being not worth my attention.
Much later, I took another look at it and discovered that hidden in the browser was an excellent programming language.
Douglas Crockford
Autor del estándar de JSON
Miembro del comité de desarrollo de Javascript
Un poco de historia
Desarrollado en solo diez días
Mocha / Livescript / JScript
Javascript / EcmaScript
Un poco de historia
Microsoft lo copia igual
Microsoft hace que AJAX sea posible con XMLHttpRequest
Y luego el mundo olvidó a Javascript
Se pierde la fe en javascript? ¿Por qué?
THE NEW WEB
Microsoft Avalon
(Silverlight)
Adobe Flash
Adobe Flex
(Adobe Air)
Sun's JavaFX
Un poco de historia
Gmail is born! there's hope!
New browser war begins
Web 2.0 happens
JSON overtakes XML
Apple kills Flash
The story so far
Javascript, al igual que HTML se convirtió
en algo totalmente diferente
en lo que se pensó originalmente
Why should I know javascript?
It's being used in all areas of Development
Web Development
Mobile Development
Gaming
Multi-platform middle layer
Productivity Software
Web Development
Web Frameworks
AngularJS, KnockoutJS, Backbone, Ember
Libraries
Breeze, underscore, jQuery, mooTools, Prototype, YUI
DOM Plugins
(too many to fit on this screen)
MOBILE
Corona SDK
MULTI-PLATFORM NATIVE
PCs, Tablets and Phones
(windows, that is)
(windows, that is)
Server side development
Gaming
2D Platforming
Multiplayer Games
Social Gaming
Game Engines comprados por Zynga y Disney:
Aves / RocketEngine
Gaming
CANVAS / WEBGL
HTML5 AUDIO
WEB SOCKETS
LOCAL STORAGE
ASM.JS
(javascript as c++)
THE GOOD PARTS
Prototype-Based / Multi-Paradigm
Dynamic / Safe Typing / First-Type Functions
C-Like Syntax (familiar to most of us)
Runs everywhere. Even on AR Drones
Google went nuts with V8
98% of code is OPEN SOURCE / FREE
First Type Functions
La habilidad que tiene un lenguaje de programación para tratar a las funciones como ciudadanos de "primera clase".
(a first-class citizen is an entity that can be constructed at run-time, passed as a parameter, returned from a subroutine, or assigned into a variable)
functions, functions, functions
Las funciones en Javascript son:
- Un método
- Una clase
- Un Constructor
- Un módulo
Function Statement
Esta declaración es un function statement:
function hacerAlgo() { }
Es igual a esta (function expression):
var hacerAlgo = function hacerAlgo() { }
Y a esta:
var hacerAlgo = function() { }
Function for class declaration
var ViewModel = function(){
var self = this;
this.nombre = ko.observable();
this.apellido = ko.observable();
}
//One way to do it
var miObjeto = new ViewModel();
//Another way to do it
var miOtroObjeto = Object.create(ViewModel);
//How NOT to do it
var miOtroObjeto = ViewModel();
Function as a module (IIFE)
//Variable global
var dinosaurio = 'velociraptor';
var ECOSISTEMA = new (function (){ var self = this; self.dinosaurio = 'Trex'; return self; })();
dinosaurio != ECOSISTEMA.dinosaurio;
prototypal inheritance
There are no classes in javascript, there's just objects:
A class definition is an object,
and an instance is also an object.
So inheritance is managed by
making objects inherit from objects
The Bad Parts
No funciona igual en
todos los browsers
Internet explorer es tu amigo
Pero...
-
Array.sort() no está implementado en el javascript engine
-
El objeto 'console' no existe
- Todos los tabs corren en la misma sesión
- getComputedStyle no funciona
NO SCOPING
//En estos dos casos la variable 'i' se refiere a la misma
for (var i=0; i< 10; i++){
console.log(i);
}
for (var i=0; i< 20; i++){
console.log(i);
}
'let' define variables con scope
pero no lo soportan todos los browsers
TRUE, TRUTHY, FALSE, FALSEY
Equality Comparer ==
REAL TRUTHINESS
Strict Equality Comparer ===
this???
- When a function is called with the 'new' operator 'this' refers to a new empty object.
- If a function is instanced without the 'new' operator, 'this' refers to the calling object.
- When this is called in any other scenario it refers to the global object (browser)
otros Macos
Whitespace
Curly Braces
Variable Hoisting
Automatic insertion of ;
Qué sigue entonces?
TODOS QUIEREN MEJORAR JAVASCRIPT
Google -> DART
Microsoft -> TypeScript
Community Based -> CoffeScript
COFFESCRIPT? SERIOUSLY?
always bet on javascript
- JS Can't be useful for Rich Internet Applications
- JS is too slow
- It can't be fixed
- It can't do multicore/GPU
JAVASCRIPT IS THE
UNIVERSAL VIRTUAL MACHINE
Thanks to all
REFERENCES
- Javascript entry on Wikipedia
- Google Javascript Engine V8
- Libros
- Blog Posts
- Brendan Eich: The web is the gaming platform
- Jeff Attwood: The lingua franca of the web
- Jon Resig: Simple Javascript Inheritance
- Javascript.info: Prototypal Inheritance Explained
- Presentaciones
Referencias (videos)
Why javascript rocks
By Ahmed Ayub
Why javascript rocks
(and why you should be using it)
- 3,571