Mod7 JavaScript 5
Mod7 JavaScript 5
Decimales:
Coma flotante:
32.23
3.2e1 (3,2x10)
10 + 4
10 - 4
10 * 4
10 / 4
10 % 4
// sumar
// restar
// multiplicar
// dividir
// operacin resto
=> 300
=> 0,03
+10/0
-10/0
=> Infinity
=> -Infinity
//desborda
//desborda
5e500
=> Infinity
//desborda
=> 14
=> 6
=> 40
=> 2.5
=> 2
Conversin a enteros
'67' + 13
Cuando JavaScript calcula expresiones
n conviendo tipos segn necesita
w segn las prioridades de operadores
Conversin a entero (o real)
n boleano: true a 1, false a 0
n String: Convierte nmero a valor o NaN
n null: a 0,
undefined: a NaN
=> 6713
+'67'
+ 13 => 80
+'6.7e1' + 13 => 80
'xx' + 13
+'xx' + 13
=> 'xx13'
=> NaN
13 + true
13 + false
=> 14
=> 13
. []
new
()
++ -! ~
+ delete
typeof void
* / %
+
+ << >> >>>
< <= > >=
instanceof in
== != === !==
&
^
|
&&
||
?:
=
OP=
,
Operadores JavaScript
Modulo Math
El Modulo Math contiene
n constantes y funciones matemticas
Constantes
n Nmeros: E, PI, SQRT2, ...
n ...
Funciones
n sin(x), cos(x), tan(x), asin(x), ....
n log(x), exp(x), pow(x, y), sqrt(x), ....
n abs(x), ceil(x), floor(x), round(x), ....
n min(x,y,z,..), max (x,y,z,..), ...
n random()
Mas info:
http://www.w3schools.com/jsref/jsref_obj_math.asp
=> 3
=> 4
=> 3
Math.sin(1)
=> 0.8414709848078965
Math.asin(0.8414709848078965) => 1
=> 9 // 3 al cuadrado
=> 3 // raz cuadrada de 3
Arrays
Array: lista ordenada de
n elementos heterogneos
w accesibles a travs de un ndice
n de 0 a length-1
Tamao mximo: 2^32-2 elementos
Elementos
n a[0] es el primer elemento
n ........
n a[a.length-1] ltimo elemento
=> 1
=> 2
=> 3
a.length
=> 3
Elementos de un Array
Elementos del array pueden
contener cualquier valor u objeto
n undefined
n otro array
n objetos
n ...
Indexar elementos que no existen
n devuelve undefined
=> undefined
=> [1, 2]
a[9];
=> undefined
a[4][1];
=> 2
que length
=> [1, 3, 1]
a[4] = 2;
a;
=> 2
=> [1, 3, 1, , 2]
// el array se reduce
a.length = 2 => 2
=> [1, 3]
Mtodos de Array
Array hereda mtodos de su clase
a.sort()
=> [1, 3, 5]
a.reverse()
=> [5, 3, 1]
a.push(false)
a
=> 4
=> [5, 3, 1, false]
a.pop()
a
=> false
=> [5, 3, 1]
10
11
JSON
JSON: formato textual de representacin de tipos y objetos JavaScript
n http://json.org/json-es.html
Un objeto JavaScript se transforma a un string JSON con
n JSON.stringify(object)
Un string JSON se transforma en el objeto original con
n JSON.parse(string_JSON)
var x = {a:1, b:{y:[false, null, ""]}},
y,
z;
y = JSON.stringify(x);
z = JSON.parse(y);
12
Serializacin de datos
Serializacin:
n transformacin reversible de un tipo u objeto (en
memoria) en un string equivalente
La serializacin es un formato de intercambio de datos
n
n
n
JSON.stringify(...) y JSON.parse(...)
13
Caractersticas de JSON
JSON puede serializar
n
No se puede serializar
w Funciones, RegExp, errores, undefined
JSON.stringify(new Date())
=> '"2013-08-08T17:13:10.751Z"'
JSON.stringify(NaN)
=> 'null'
JSON.stringify(Infinity)
=> 'null'
Juan Quemada, DIT, UPM
14
15
http://commons.wikimedia.org/wiki/File:Compass.svg
http://commons.wikimedia.org/wiki/SVG_examples
16
17
Ejemplo SVG
18
19
Reloj SVG
Juan Quemada, DIT, UPM
Sunday, February 23, 14
20
21
22
23
Objetos SVG
Los objetos SVG se pueden definir tambin como objetos externos en XML
n Para importarlos con:
w <img>, <object>, <embed>, <iframe>
n Tutorial: http://tavmjong.free.fr/INKSCAPE/MANUAL/html/Web-Use.html
24
Sunday, February 23, 14
HTML5 CANVAS
25
Tutoriales
n
n
n
https://developer.mozilla.org/En/Canvas_tutorial
http://www.desarrolloweb.com/manuales/manual-canvas-html5.html
http://www.html5canvastutorials.com/
Juan Quemada, DIT, UPM
26
27
Reloj CANVAS
Juan Quemada, DIT, UPM
Sunday, February 23, 14
28
29
CANVAS:
Reloj animado
Juan Quemada, DIT, UPM
Sunday, February 23, 14
30
WebGL: Web en 3D
http://www.chromeexperiments.com/webgl
31
32
33
Video: formatos
Contenedor OGG
n Video: Theora (VP7), Audio: Vorbis
w Calidad menor
Contenedor MP4
n Video: H264, Audio: ACC
w Existen Patentes
Contenedor WebM
n Video: VP8, Audio: Vorbis
34
iFrame
n marco de navegacin independiente
iFrame
35
Origen
n
36
37