SlideShare a Scribd company logo
1 of 174
Javascript
     do jeito certo


     Alexandre Gomes
javascript
                      ?
a que te remete o termo
<form>
  <input type=button
         value="Close Window"
         onClick="javascript:window.close();">
</form>
<script>
  function open_window(url) {
     mywin = window.open(url,"win",...);
  }
</script>

<body>
  <a href = "javascript:open_window('page1.html')">
     <img src ="image.gif">
  </a>
  <a href = "javascript:open_window('page2.html')">
     <img src ="image.gif">
  </a>
</body>
function validateForm() {
  var x = document.forms["myForm"]["fname"].value
  if (x == null || x == "") {
     alert("Nome obrigatĆ³rio!");
     return false;
  }
}
para a grande maioria,

javascript = magia negra
Javascript
http://corte.si/posts/code/devsurvey/index.html
https://github.com/blog/99-popular-languages
javascript
Aļ¬nal,



         Ć© do mal ou do bem?
http://www.ecma-international.org/publications/standards/Ecma-262.htm
ISO IEC
                     16262


http://www.ecma-international.org/publications/standards/Ecma-262.htm
ā€œ         ECMAScript is an
         object-oriented
          programming
       language for performing
    computations and manipulating
     computational objects within
         a host environment.

          ECMAScript Language Speciļ¬cation
            5th edition (December 2009)
ā€œ      ECMAScript as deļ¬ned here
       is not intended to be
      computationally self-
    sufficient; indeed, there are no
    provisions in this speciļ¬cation for
    input of external data or output of
            computed results.

            ECMAScript Language Speciļ¬cation
              5th edition (December 2009)
ā€œ       Instead, it is expected that
    the computational environment
            (host environment)
      of an ECMAScript program will
     provide not only the objects and
     other facilities described in this
       speciļ¬cation but also certain
       environment-speciļ¬c host
                   objects
            ECMAScript Language Speciļ¬cation
              5th edition (December 2009)
ā€œ        Some of the facilities of
     ECMAScript are similar to those
       used in other programming
    languages; in particular Java  TM,
            Self, and Scheme


           ECMAScript Language Speciļ¬cation
             5th edition (December 2009)
ā€œ   A web browser provides an ECMAScript host
      environment for client-side computation
         including, for instance, objects that
       represent windows, menus, pop-ups,
    dialog boxes, text areas, anchors, frames,
        history, cookies, and input/output.



    navigator.appName;
    window.moveTo(100,100);


             ECMAScript Language Speciļ¬cation
               5th edition (December 2009)
ā€œ     Further, the host environment provides a
     means to attach scripting code to events such
        as change of focus, page and image
        loading, unloading, error and abort,
      selection, form submission, and mouse
                       actions.



<button type="button" onclick="displayDate()">
   Display Date
</button>



              ECMAScript Language Speciļ¬cation
                5th edition (December 2009)
ā€œ           The scripting code is reactive
               to user interaction and
       there is no need for a main program.


<!-- Ate parece, mas nao e o ā€˜mainā€™ do javascript -->
<script type="text/javascript">
 function load() {
   alert("Page is loaded");
 }
</script>

<body onload="load()">

                ECMAScript Language Speciļ¬cation
                  5th edition (December 2009)
ā€œ   A web server provides a different
    host environment for server-side
      computation including objects
     representing requests, clients,
      and ļ¬les; and mechanisms to
          lock and share data.


           ECMAScript Language Speciļ¬cation
             5th edition (December 2009)
ā€œ   Each Web browser and server that
       supports ECMAScript supplies
     its own host environment,
        completing the ECMAScript
          execution environment.


           ECMAScript Language Speciļ¬cation
             5th edition (December 2009)
ā€œ   ECMAScript is an object-oriented
    programming language
                           (...)




          ECMAScript Language Speciļ¬cation
            5th edition (December 2009)
ā€œ     ECMAScript is an object-oriented
      programming language
                                 (...)


      Tipos    Boolean, Number, String, Array, RegExp


Operadores     + - * / >> << >>> < > <= >= | & *= ^ ++

ComentƔrios    //    /*       */

  Estruturas   do while for if else try catch switch



                ECMAScript Language Speciļ¬cation
                  5th edition (December 2009)
Tipos
          (construtores)



Boolean                    Object
Number                Function
String                     RegExp
 Array                      Date
Tipos
              undeļ¬ned




var x;
alert(x);




       ECMAScript Language Speciļ¬cation
         5th edition (December 2009)
Tipos
                   null




var x = null;
alert(x);




       ECMAScript Language Speciļ¬cation
         5th edition (December 2009)
Tipos
                             Boolean



var x = true;
if(x) {
  alert('Verdadeiro');
}

Obs: 0 e null equivalem a false




                   ECMAScript Language Speciļ¬cation
                     5th edition (December 2009)
Tipos
                 Number


var x = 10;
var y = 15;
alert(x+y);


var x = 10.1;
var y = 15.2;
alert(x+y);


        ECMAScript Language Speciļ¬cation
          5th edition (December 2009)
Tipos
                 String



var x = ā€œAlexandreā€;
alert(x);




      ECMAScript Language Speciļ¬cation
        5th edition (December 2009)
Tipos
                  Function


var x = function() { alert("Alexandre"); };
x();




          ECMAScript Language Speciļ¬cation
            5th edition (December 2009)
> var x = true;
> x.constructor;
Boolean()

> var x = "Alexandre";
> x.constructor;
String()

> var x = 3467;
> x.constructor;
Number()

> var x = function() { alert("Alexandre"); };
> x.constructor;
Function()
var x = new Boolean(true);
if(x) { alert('Verdadeiro'); }




var x = new String(ā€œAlexandreā€);
alert(x);




var x = new Number(10);
var y = new Number(15);
alert(x+y);
Operadores
             /        <<=   ? :
delete
             %        >>=    =
 void
             >>        ==    *=
typeof
             <<       !=     /=
  ++
            >>>       ===    %=
  --
             <        !==    +=
  +
             >         &     -=
  -
             <=        ^    >>>=
  ~
             >=        |     &=
  !
         instanceof   &&     Ė†=
  *                   ||
             in              |=
Operadores
                   delete

var a = 1
undeļ¬ned
a
1
delete a
true
a
ReferenceError: a is not deļ¬ned
           ECMAScript Language Speciļ¬cation
             5th edition (December 2009)
Operadores
                        typeof

typeof 1
"number"
typeof true
"boolean"
typeof "Alexandre"
"string"
typeof function() { alert('Oi') }
"function"
typeof null
"object"
                ECMAScript Language Speciļ¬cation
                  5th edition (December 2009)
Operadores
                   ++ e --

var a = 1
undeļ¬ned
a++
1
a
2
++a
3
            ECMAScript Language Speciļ¬cation
              5th edition (December 2009)
Operadores
                 instanceof

var a = "alexandre"
undeļ¬ned
a instanceof String
false
var a = new String("alexandre")
undeļ¬ned
a instanceof String
true
a instanceof Object
true
              ECMAScript Language Speciļ¬cation
                5th edition (December 2009)
Operadores
            ==, !=, ===, !==

3 == "3"
true
3 === "3"
false

2 != "2"
false
2 !== "2"
true
             ECMAScript Language Speciļ¬cation
               5th edition (December 2009)
Estruturas


if/else    continue      switch
do/while     break        throw
 while      return      try/catch
  for        with       debugger
 for/in
Estruturas
                   if/else

var a = true

if (a) {
  alert('Verdadeiro')
} else {
  alert('Falso')
}
            ECMAScript Language Speciļ¬cation
              5th edition (December 2009)
Estruturas
               do/while


var i = 1
do {
  alert(i);                                  (...)

  i++;
} while (i < 5)

          ECMAScript Language Speciļ¬cation
            5th edition (December 2009)
Estruturas
                        for


for ( var i = 1; i < 5; i++) {
  alert(i);
}


                       (...)



            ECMAScript Language Speciļ¬cation
              5th edition (December 2009)
Estruturas
                       for/in

var array = [1,3,5,7,9]

for (var i in array) {
  alert(array[i])
}


                          (...)



               ECMAScript Language Speciļ¬cation
                 5th edition (December 2009)
Estruturas
                    for/each/in
> var obj = { a: 1, b: 3, c: 5 }

> obj.a
1

> for(p in obj) {
   alert(p + ": " + obj[p])
 }

> for each (v in obj) {
   alert(v) // v aqui igual ao obj[p] acima
 }
                  ECMAScript Language Speciļ¬cation
                    5th edition (December 2009)
Estruturas
                            with

var obj = { a: 1, b: 3, c: 5 }

alert(obj.a); // 1
alert(obj.b); // 3
alert(obj.c); // 5

with(obj) {
 alert(a); // 1
 alert(b); // 3
 alert(c); // 5
}
                  ECMAScript Language Speciļ¬cation
                    5th edition (December 2009)
Estruturas
                         switch/case
var a = "alexandre";

switch (a) {

case "sebastiao":
 alert("TiĆ£o?");
 break;

case "raimunda":
 alert("Raimundinha?");
 break;

 case "alexandre":
  alert("AlĆŖ!");
  break;
}
                       ECMAScript Language Speciļ¬cation
                         5th edition (December 2009)
ā€œ      ECMAScript is object-based: basic
    language and host facilities are provided by
      objects, and an ECMAScript program is a
         cluster of communicating objects.




             ECMAScript Language Speciļ¬cation
               5th edition (December 2009)
Numa aplicaĆ§Ć£o Javascript, coexistirĆ£o

  3 grupos de objetos
objetos deļ¬nidos pela   objetos deļ¬nidos pelo   objetos deļ¬nidos pelo
 especiļ¬caĆ§Ć£o           web browser             desenvolvedor
 ECMAScript

     Boolean                 window                 alexandre
     Number                 document               mensagem
      String            XMLHttpRequest                   ...
      Array                      ...
       ...
ā€œ            An ECMAScript object is a
         collection of properties
      each with zero or more attributes
    that determine how each property can be used

                    alexandre


             nome: ā€œAlexandreā€
             sobrenome: ā€œGomesā€
             idade: 34




            ECMAScript Language Speciļ¬cation
              5th edition (December 2009)
ā€œ            An ECMAScript object is a
         collection of properties
      each with zero or more attributes
    that determine how each property can be used

                    alexandre


             nome: ā€œAlexandreā€
             sobrenome: ā€œGomesā€
             idade: 34
                   modiļ¬cĆ”vel: false



            ECMAScript Language Speciļ¬cation
              5th edition (December 2009)
> var ale = new Object()

> ale.nome = "Alexandre Gomes"
"Alexandre Gomes"
> ale.nascimento = new Date(1977,8,8)
Thu Sep 08 1977 00:00:00 GMT-0300 (BRT)

> ale.nome
"Alexandre Gomes"
> ale.nascimento
Thu Sep 08 1977 00:00:00 GMT-0300 (BRT)

> ale[ā€˜nomeā€™]
"Alexandre Gomes"
> ale[ā€˜nascimentoā€™]
Thu Sep 08 1977 00:00:00 GMT-0300 (BRT)
ā€œ   Properties are containers (slots) that hold
       other objects, primitive values, or
                    functions.


                     alexandre

    nome: ā€œAlexandreā€
    nascimento: new Date(1977,8,8,0,0,0,0)
    idade: function() { ... }




             ECMAScript Language Speciļ¬cation
               5th edition (December 2009)
ā€œ   ECMAScript deļ¬nes a
collection of built-in objects
Function, Array, String, Boolean, Number, Math, Date, RegExp, JSON
           Error, EvalError, RangeError, ReferenceError,
               SyntaxError, TypeError e URIError




                 ECMAScript Language Speciļ¬cation
                   5th edition (December 2009)
> var x = "Alexandre";
> x.length
                                    String
9
> x.charAt(5);
"n"
> x + " Gomes"
"Alexandre Gomes"
> x.replace("dre", "dro");
"Alexandro"
> x.big()
"<big>Alexandre</big>"
> x.link("http://alegom.es")
"<a href="http://alegom.es">Alexandre</a>"
Boolean
>>> var x = true;
>>> if(x) { alert('yes'); } else { alert('no') } // yes

>>> !x
false

>>> x   & false
0
>>> x   && false
false
>>> x   | false
1
>>> x   || false
true

>>> var x = false;
>>> if(x) { alert('yes'); } else { alert('no') } // no
Number
>>> var x = 10
>>> var y = 15;
>>> z = x + y
25

>>> z.toFixed(2);
"25.00"

>>> z.toExponential(2);
"2.50e+1"

>>> 2.toExponential(2);
SyntaxError: identifier starts immediately
after numeric literal
Math
>>> Math.PI
3.141592653589793
>>> Math.sqrt(81);
9
>>> Math.tan(45);
1.6197751905438615
>>> Math.pow(3,2);
9
>>> Math.random();
0.8528815588353642
>>> Math.random();
0.955940929887219
>>> var x = new Date();                                Date
>>> x.toString();
"Sun Apr 03 2011 12:20:42 GMT-0300 (BRT)"

>>> x.getHours() + ":" + x.getMinutes() + ":" + x.getSeconds();
"12:20:42"

>>> x.getDate() + "/" + x.getMonth() + "/" + x.getFullYear();
"3/3/2011"

>>> var x = new Date("5/18/2006");
>>> x.toString();
"Thu May 18 2006 00:00:00 GMT-0300 (BRT)"

>>> var x = new Date("2006-5-18");
>>> x.toString();
"Invalid Date"

>>> var x = Date(2006,5,18,10,11,12,13);
>>> x.toString();
"Sun Jun 18 2006 10:11:12 GMT-0300 (BRT)"
>>> var x = new Date();
>>> x.toString();
                                                       Date
"Sun Apr 03 2011 12:20:42 GMT-0300 (BRT)"

>>> x.getHours() + ":" + x.getMinutes() + ":" + x.getSeconds();
"12:20:42"

>>> x.getDate() + "/" + x.getMonth() + "/" + x.getFullYear();
"3/3/2011"

>>> var x = new Date("5/18/2006");
>>> x.toString();
"Thu May 18 2006 00:00:00 GMT-0300 (BRT)"

>>> var x = new Date("2006-5-18");
>>> x.toString();
"Invalid Date"

>>> var x = Date(2006,5,18,10,11,12,13);
>>> x.toString();
"Sun Jun 18 2006 10:11:12 GMT-0300 (BRT)"
>>> var texto = "O gato roeu a roupa do rei de roma";
>>> var regex = new RegExp("gato", ā€œā€);

>>> texto.match(regex);
["gato"]
                                            Regex
>>> regex.exec(texto);
["gato"]

>>> texto.match(/gato/);
["gato"]

>>> texto.match(/O gato/);
["O gato"]
>>> texto.match(/o gato/);
null
>>> texto.match(/o gato/i);
["O gato"]

>>> texto.match(/o gato.*/i);
["O gato roeu a roupa do rei de roma"]
>>> var obj = { "nome": "Alexandre", "idade" : "33" }
>>> obj.constructor;
Object()                                                  JSON
>>> obj.nome
"Alexandre"
>>> obj.idade
"33"

>>> var msg = JSON.stringify(obj);
>>> msg.constructor;
String()
>>> msg
"{"nome":"Alexandre","idade":"33"}"

>>> var msg = '{ "nome": "Alexandre", "idade" : "33" }'
"{ "nome": "Alexandre", "idade" : "33" }"
>>> msg.constructor;
String()
>>> msg.nome;
undefined

>>> obj = JSON.parse(msg);
Object { nome="Alexandre", idade="33"}
>>> obj.constructor;
Object()
>>> obj.nome;
"Alexandre"
var x = new Array();
>>> []                                    Array
x[0] = "laranja"
>>> ["laranja"]

x[2] = "maĆ§Ć£"
>>> ["laranja", undefined, "maĆ§Ć£"]

x.length
>>> 3

x.sort();
>>> ["laranja", "maĆ§Ć£", undefined]

x.reverse();
>>> [undefined, "maĆ§Ć£", "laranja"]

x = ["pera", "uva", new Date()]
x.toString();
>>> "pera,uva,Sun Apr 03 2011 11:53:18 GMT-0300 (BRT
ā€œ    A web browser provides an
    ECMAScript host environment
                (...)
> document.body
 1. <body id=ā€‹"docs" class=ā€‹"section-docs en ltr yui-skin-sam PageDW-
    enDOMdocument js" role=ā€‹"document">ā€‹ā€¦ā€‹</body>ā€‹

> document.domain
"developer.mozilla.org"

> document.links
[
  <a href=ā€‹"#content-main">ā€‹Skip to the main contentā€‹</a>,
   <a href=ā€‹"#q">ā€‹Skip to the site searchā€‹</a>,
   <a href=ā€‹"/ā€‹">ā€‹ā€¦ā€‹</a>,
   <a href=ā€‹"/ā€‹index.php?" class=ā€‹"user-login">ā€‹Log inā€‹</a>,
   <a href=ā€‹"/ā€‹docs">ā€‹Doc Centerā€‹</a>,
   ā€¦
{
{
Gecko   Webkit
e agora, prendam
  a respiraĆ§Ć£o...
ā€œ   apesar de ser OO,

 ECMAScript does not use
classes such as those in C+
    +, Smalltalk, or Java.




                   ECMAScript Language Speciļ¬cation
                     5th edition (December 2009)
ā€œClassfulā€             ā€œClasslessā€
reuso por heranƧa de    reuso por clonagem
       classes              de objetos


      Pessoa                   joao

       nome                 nome: ā€œJoĆ£oā€
       sexo                  idade: 28


            <<herda>>                 <<clona>>

     FuncionƔri               maria
         o
       salĆ”rio             nome: ā€œMariaā€
                             idade: 20
ā€œClassfulā€                ā€œClasslessā€
   modelagem                 modelagem
   top-down                  bottom-up




primeiro a taxonomia e        primeiro o
seus relacionamentos...    comportamento...
ā€œClassfulā€           ā€œClasslessā€

objetos criados a      objetos criados a
partir de classes    partir de clonagem...


hoje = new Date()   hoje = new Date()


                      ...ou por ā€˜geraĆ§Ć£o
                          expontĆ¢neaā€™
                    var x = {
                      one: 1,
                      two: 2
                    }
ā€œClassfulā€            ā€œClasslessā€


objetos carregam a   objetos carregam as
   estrutura e o      caracterĆ­sticas de
 comportamento
   de sua classe      seu protĆ³tipo
ProgramaĆ§Ć£o baseada em

   protĆ³tipos


protĆ³tipo
ProgramaĆ§Ć£o baseada em

   protĆ³tipos


protĆ³tipo               clone
ProgramaĆ§Ć£o baseada em

   protĆ³tipos


protĆ³tipo               clone
ProgramaĆ§Ć£o baseada em

              protĆ³tipos
>>> var conta = { saldo: 1000.00 };
>>> conta.saldo
1000
>>> conta.limite
undefined

>>> var conta_especial = { limite: 500.00 }
>>> conta_especial.limite
500
>>> conta_especial.saldo
undefined

>>> conta_especial.__proto__ = conta // referĆŖncia explĆ­cita
Object { saldo=1000}
>>> conta_especial.saldo
1000
HeranƧa baseada em

                     protĆ³tipos
> var conta = function(saldo) {
   this.saldo = saldo;
   this.ver_saldo = function() {
     alert('saldo = ' + this.saldo)
   }
 }

> c1 = new conta(1000)
> c1.ver_saldo()

> var conta_especial = function(saldo, limite) {
   this.inheritFrom = conta;
   this.inheritFrom();
   this.saldo = saldo;
   this.limite = limite;
 }

> c2 = new conta_especial(2000,3000)
> c2.ver_saldo()
ā€œ   objects may be created in
     various ways including
      via a literal notation
      var conta = { saldo: 1000.00 }




          ECMAScript Language Speciļ¬cation
            5th edition (December 2009)
ā€œ   objects may be created in
     various ways including
      via a literal notation
      var conta = { saldo: 1000.00 }


       or via constructors
      hoje = new Date()
          ECMAScript Language Speciļ¬cation
            5th edition (December 2009)
ā€œ   Each constructor
      is a function
       hoje = new Date()


    function Date() {
    ...
    }

      ECMAScript Language Speciļ¬cation
        5th edition (December 2009)
mas
    function Ʃ tambƩm um
            objeto

                          Date()
var Date = function() {
...
}

hoje = new Date()
construtor


 function    Date()




 objeto
construtor


 function      Date()




  objeto


propriedades
ā€œ  Each constructor is a
function that has a property
named ā€œprototypeā€ that
   is used to implement
prototype-based inheritance
    and shared properties.
         ECMAScript Language Speciļ¬cation
           5th edition (December 2009)
ā€œ   Each constructor is a function that has a
        property named ā€œprototypeā€(...)



     Date()
    <<construtor

     prototype




                               ProtĆ³tipo
                               do Date()


                   ECMAScript Language Speciļ¬cation
                     5th edition (December 2009)
Date()
<<construtor

prototype




                           ProtĆ³tipo
                           do Date()


               ECMAScript Language Speciļ¬cation
                 5th edition (December 2009)
ā€œ   Every object created by a constructor




     Date()
    <<construtor      hoje = new Date()               hoje
    prototype




                               ProtĆ³tipo
                               do Date()


                   ECMAScript Language Speciļ¬cation
                     5th edition (December 2009)
ā€œ   Every object created by a constructor
    has an implicit reference (called the objectā€™s prototype)




     Date()
     <<construtor      hoje = new Date()                hoje
     prototype                                         prototype




                                ProtĆ³tipo
                                do Date()


                    ECMAScript Language Speciļ¬cation
                      5th edition (December 2009)
ā€œ   Every object created by a constructor
    has an implicit reference (called the objectā€™s prototype)
     to the value of its constructorā€™s ā€œprototypeā€ property.



     Date()
     <<construtor      hoje = new Date()                hoje
     prototype                                         prototype




                                ProtĆ³tipo
                                do Date()


                    ECMAScript Language Speciļ¬cation
                      5th edition (December 2009)
ā€œ        Furthermore, a prototype may have a
           non-null implicit reference to its
        prototype, and so on; this is called the
                prototype chain.

    Date()
    <<construtor




                           ProtĆ³tipo
                           do Date()


                   ECMAScript Language Speciļ¬cation
                     5th edition (December 2009)
ā€œ        Furthermore, a prototype may have a
           non-null implicit reference to its
        prototype, and so on; this is called the
                prototype chain.

    Date()
    <<construtor                           ProtĆ³tipo do
                                           protĆ³tipo do
                                              Date()




                                                          ProtĆ³tipo do
                           ProtĆ³tipo                      protĆ³tipo do
                           do Date()                      protĆ³tipo do
                                                             Date()



                   ECMAScript Language Speciļ¬cation
                     5th edition (December 2009)
ā€œ   When a reference is made to a property in
        an object, that reference is to the
     property of that name in the ļ¬rst object
      in the prototype chain that contains a
              property of that name.




             ECMAScript Language Speciļ¬cation
               5th edition (December 2009)
ā€œ       When a reference is made to a property in
            an object, that reference is to the
         property of that name in the ļ¬rst object
          in the prototype chain that contains a
                  property of that name.


  obj
                              p3:
p1: ā€œumā€                     ā€œtresā€




                 p2:                         p4:
                ā€œdoisā€                     ā€œquatroā€




                 ECMAScript Language Speciļ¬cation
                   5th edition (December 2009)
ā€œ       When a reference is made to a property in
            an object, that reference is to the
         property of that name in the ļ¬rst object
          in the prototype chain that contains a
                  property of that name.


  obj                                                 obj.p1
                              p3:
p1: ā€œumā€                     ā€œtresā€




                 p2:                         p4:
                ā€œdoisā€                     ā€œquatroā€




                 ECMAScript Language Speciļ¬cation
                   5th edition (December 2009)
ā€œ       When a reference is made to a property in
            an object, that reference is to the
         property of that name in the ļ¬rst object
          in the prototype chain that contains a
                  property of that name.


  obj                                                 obj.p1
                              p3:
p1: ā€œumā€                     ā€œtresā€                   obj.p2


                 p2:                         p4:
                ā€œdoisā€                     ā€œquatroā€




                 ECMAScript Language Speciļ¬cation
                   5th edition (December 2009)
ā€œ       When a reference is made to a property in
            an object, that reference is to the
         property of that name in the ļ¬rst object
          in the prototype chain that contains a
                  property of that name.


  obj                                                 obj.p1
                              p3:
p1: ā€œumā€                     ā€œtresā€                   obj.p2
                                                      obj.p3
                 p2:                         p4:
                ā€œdoisā€                     ā€œquatroā€




                 ECMAScript Language Speciļ¬cation
                   5th edition (December 2009)
ā€œ       When a reference is made to a property in
            an object, that reference is to the
         property of that name in the ļ¬rst object
          in the prototype chain that contains a
                  property of that name.


  obj                                                 obj.p1
                              p3:
p1: ā€œumā€                     ā€œtresā€                   obj.p2
                                                      obj.p3
                 p2:                         p4:
                                                      obj.p4
                ā€œdoisā€                     ā€œquatroā€




                 ECMAScript Language Speciļ¬cation
                   5th edition (December 2009)
> var Pessoa = function(nome, idade) {
    this.nome = nome;
    this.idade = idade;
  }


> var alexandre = new Pessoa('Ale', 33);
> alexandre.nome
"Ale"
> alexandre.idade
33


> var sebastiana = new Pessoa('Sebastiana', 88);
> sebastiana.nome
"Sebastiana"
> sebastiana.idade
88
> var Pessoa = function(nome, idade) {
    this.nome = nome;
    this.idade = idade;
  }                            construtor


> var alexandre = new Pessoa('Ale', 33);
> alexandre.nome
"Ale"
> alexandre.idade
33


> var sebastiana = new Pessoa('Sebastiana', 88);
> sebastiana.nome
"Sebastiana"
> sebastiana.idade
88
> var Pessoa = function(nome, idade) {
    this.nome = nome;
    this.idade = idade;
  }


> var alexandre = new Pessoa('Ale', 33);
> alexandre.nome
"Ale"
> alexandre.idade
33                                objeto 1


> var sebastiana = new Pessoa('Sebastiana', 88);
> sebastiana.nome
"Sebastiana"
> sebastiana.idade
88
> var Pessoa = function(nome, idade) {
    this.nome = nome;
    this.idade = idade;
  }


> var alexandre = new Pessoa('Ale', 33);
> alexandre.nome
"Ale"
> alexandre.idade
33


> var sebastiana = new Pessoa('Sebastiana', 88);
> sebastiana.nome
"Sebastiana"
> sebastiana.idade
88                                       objeto 2
Pessoa()
<<construtor>

   nome
   idade
ProtĆ³tipo do
   Pessoa()




Pessoa()
<<construtor>

   nome
   idade
ProtĆ³tipo do
                  Pessoa()




               Pessoa()
               <<construtor>

                  nome
                  idade




alexandre                       sebastiana

nome = ā€˜Aleā€™                   nome = ā€˜Seb...ā€™
 idade = 33                      idade = 88
ProtĆ³tipo do
                  Pessoa()

                                                                ?
                                                 > alexandre.nome




               Pessoa()
               <<construtor>

                  nome
                  idade




alexandre                       sebastiana

nome = ā€˜Aleā€™                   nome = ā€˜Seb...ā€™
 idade = 33                      idade = 88
ProtĆ³tipo do                     > alexandre.nome
                  Pessoa()
                                                 ā€œAleā€




               Pessoa()
               <<construtor>

                  nome
                  idade




alexandre                       sebastiana

nome = ā€˜Aleā€™                   nome = ā€˜Seb...ā€™
 idade = 33                      idade = 88
ProtĆ³tipo do                     > alexandre.nome
                  Pessoa()
                                                 ā€œAleā€

                                                 > sebastiana.idade
                                                 88

               Pessoa()
               <<construtor>

                  nome
                  idade




alexandre                       sebastiana

nome = ā€˜Aleā€™                   nome = ā€˜Seb...ā€™
 idade = 33                      idade = 88
ProtĆ³tipo do                     > alexandre.nome
                  Pessoa()
                                                 ā€œAleā€

                                                 > sebastiana.idade
                                                 88

               Pessoa()


                                                                 ?
               <<construtor>
                                                 > alexandre.sexo
                  nome
                  idade




alexandre                       sebastiana

nome = ā€˜Aleā€™                   nome = ā€˜Seb...ā€™
 idade = 33                      idade = 88
ProtĆ³tipo do                     > alexandre.nome
                  Pessoa()
                                                 ā€œAleā€

                                                 > sebastiana.idade
                                                 88

               Pessoa()
               <<construtor>
                                                 > alexandre.sexo
                  nome
                                                 undefined
                  idade




alexandre                       sebastiana

nome = ā€˜Aleā€™                   nome = ā€˜Seb...ā€™
 idade = 33                      idade = 88
ProtĆ³tipo do                     > alexandre.nome
                  Pessoa()
                                                 ā€œAleā€

                                                 > sebastiana.idade
                                                 88

               Pessoa()
               <<construtor>
                                                 > alexandre.sexo
                  nome
                                                 undefined
                  idade
                                                 > sebastiana.sexo
                                                 undefined

alexandre                       sebastiana

nome = ā€˜Aleā€™                   nome = ā€˜Seb...ā€™
 idade = 33                      idade = 88
ProtĆ³tipo




               Pessoa()
               <<construtor>

                  nome
                  idade




alexandre                       sebastiana

nome = ā€˜Aleā€™                   nome = ā€˜Seb...ā€™
 idade = 33                      idade = 88
ProtĆ³tipo           > Pessoa.prototype.sexo = ā€œMā€

                  sexo



               Pessoa()
               <<construtor>

                  nome
                  idade




alexandre                       sebastiana

nome = ā€˜Aleā€™                   nome = ā€˜Seb...ā€™
 idade = 33                      idade = 88
ProtĆ³tipo           > Pessoa.prototype.sexo = ā€œMā€

                  sexo                            > alexandre.sexo
                                                              ā€œMā€



               Pessoa()
               <<construtor>

                  nome
                  idade




alexandre                       sebastiana

nome = ā€˜Aleā€™                   nome = ā€˜Seb...ā€™
 idade = 33                      idade = 88
ProtĆ³tipo           > Pessoa.prototype.sexo = ā€œMā€

                  sexo                            > alexandre.sexo
                                                              ā€œMā€
                                                 > sebastiana.sexo
                                                              ā€œMā€
               Pessoa()
               <<construtor>

                  nome
                  idade




alexandre                       sebastiana

nome = ā€˜Aleā€™                   nome = ā€˜Seb...ā€™
 idade = 33                      idade = 88
ProtĆ³tipo           > Pessoa.prototype.sexo = ā€œMā€

                  sexo                                  > alexandre.sexo
                                                                    ā€œMā€
                                                       > sebastiana.sexo
                                                                    ā€œMā€
               Pessoa()
               <<construtor>

                  nome                           > sebastiana.sexo = ā€œFā€
                  idade




alexandre                       sebastiana

nome = ā€˜Aleā€™                   nome = ā€˜Seb...ā€™
 idade = 33                      idade = 88
ProtĆ³tipo           > Pessoa.prototype.sexo = ā€œMā€

                  sexo                                  > alexandre.sexo
                                                                    ā€œMā€
                                                       > sebastiana.sexo
                                                                    ā€œMā€
               Pessoa()
               <<construtor>

                  nome                           > sebastiana.sexo = ā€œFā€
                  idade
                                                       > sebastiana.sexo
                                                                    ā€œFā€


alexandre                       sebastiana

nome = ā€˜Aleā€™                   nome = ā€˜Seb...ā€™
 idade = 33                      idade = 88
Object
Object   Prototipo de Object
Object    Prototipo de Object




Object.prototype.pO = 1
Object    Prototipo de Object

                pO = 1




Object.prototype.pO = 1
Object      Prototipo de Object

                 pO = 1



  A

 a=2


var A = function() {
  this.a = 2;
}
Object   Prototipo de Object

              pO = 1



  A       Prototipo de A

 a=2
Object    Prototipo de Object

               pO = 1



  A        Prototipo de A

 a=2           pA = 3




A.prototype.pA = 3
Object        Prototipo de Object

                   pO = 1



  A            Prototipo de A

 a=2               pA = 3



  B      var B = function() {
           this.b = 4;
b=4
         }
Object   Prototipo de Object

              pO = 1



  A       Prototipo de A

 a=2          pA = 3



  B       Prototipo de B

b=4
Object        Prototipo de Object

      B.prototype = new A
                pO = 1



  A            Prototipo de A

 a=2               pA = 3



  B            Prototipo de B

b=4
Object        Prototipo de Object

      B.prototype = new A
                pO = 1



  A            Prototipo de A

 a=2               pA = 3



  B
                   new A()
b=4
Object       Prototipo de Object

      B.prototype.pB = 5
                pO = 1



  A           Prototipo de A

 a=2              pA = 3



  B
                  new A()
b=4
                  pB = 5
Object   Prototipo de Object

              pO = 1



  A       Prototipo de A

 a=2          pA = 3



  B
              new A()
b=4
              pB = 5
Object       Prototipo de Object

         x = new= 1
               pO
                  B()

  A           Prototipo de A

 a=2              pA = 3



  B
                  new A()          X
b=4
                  pB = 5
Object   Prototipo de Object

              pO = 1



  A       Prototipo de A

 a=2          pA = 3



  B
              new A()          X
b=4
              pB = 5
Object   Prototipo de Object

              pO = 1



  A       Prototipo de A

 a=2          pA = 3
                               x.pB
                                    ?
  B
              new A()           X
b=4
              pB = 5
Object   Prototipo de Object

              pO = 1



  A       Prototipo de A

 a=2          pA = 3
                               x.b

  B
              new A()           X
b=4
              pB = 5
Object   Prototipo de Object

              pO = 1



  A       Prototipo de A

 a=2          pA = 3
                               x.b
                                     ?
  B
              new A()           X
b=4
              pB = 5
Object   Prototipo de Object

              pO = 1



  A       Prototipo de A

 a=2          pA = 3
                               x.pA

  B
              new A()            X
b=4
              pB = 5
Object   Prototipo de Object

              pO = 1



  A       Prototipo de A

 a=2          pA = 3
                               x.pA
                                     ?
  B
              new A()            X
b=4
              pB = 5
Object   Prototipo de Object

              pO = 1



  A       Prototipo de A

 a=2          pA = 3
                               x.a

  B
              new A()           X
b=4
              pB = 5
Object   Prototipo de Object

              pO = 1



  A       Prototipo de A

 a=2          pA = 3
                               x.a
                                     ?
  B
              new A()           X
b=4
              pB = 5
Object   Prototipo de Object

              pO = 1



  A       Prototipo de A

 a=2          pA = 3
                               x.pO

  B
              new A()            X
b=4
              pB = 5
Object   Prototipo de Object

              pO = 1



  A       Prototipo de A

 a=2          pA = 3
                               x.pO
                                     ?
  B
              new A()            X
b=4
              pB = 5
@see
        http://www.w3schools.com/js/default.asp

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

https://developer.mozilla.org/en/Gecko_DOM_Reference

http://developer.apple.com/library/safari/#documentation/
AppleApplications/Reference/WebKitDOMRef/index.html
o que tem sido
       feito com
javascript
http://jquery.com/
http://plugins.jquery.com/

ā€¢   Ajax
                               ā€¢   Layout
ā€¢   Animation and Effects
                               ā€¢   Media
ā€¢   Browser Tweaks
                               ā€¢   Menus
ā€¢   Data
                               ā€¢   Metaplugin
ā€¢   DOM
                               ā€¢   Navigation
ā€¢   Drag-and-Drop
                               ā€¢   Tables
ā€¢   Events
                               ā€¢   User Interface
ā€¢   Forms
                               ā€¢   Utilities
ā€¢   Integration
                               ā€¢   Widgets
ā€¢   JavaScript
                               ā€¢   Windows and Overlays
ā€¢   jQuery Extensions
http://www.prototypejs.org/
http://script.aculo.us/
http://madrobby.github.com/scriptaculous/combination-effects-demo/
http://raphaeljs.com/
Node's goal is to provide an
easy way to build scalable
   network programs.


        http://nodejs.org/
Backbone supplies structure to JavaScript-heavy
 applications by providing models with key-value
binding and custom events, collections with a rich
API of enumerable functions, views with declarative
 event handling, and connects it all to your existing
     application over a RESTful JSON interface.


      http://documentcloud.github.com/backbone/
CoffeeScript is a little language
that compiles into JavaScript. (...)
   CoffeeScript is an attempt to
     expose the good parts of
    JavaScript in a simple way.


    http://jashkenas.github.com/coffee-script/
if (opposite) {
      number = -42;
    }




number = -42 if opposite
square = function(x) {
   return x * x;
};




square = (x) -> x * x
cubes = (function() {
  var _i, _len, _results;
  _results = [];
  for (_i = 0, _len = list.length; _i < _len; _i++) {
    num = list[_i];
    _results.push(math.cube(num));
  }
  return _results;
})();




   cubes = (math.cube num for num in list)
P&R
Javascript do jeito certo

More Related Content

What's hot

002. Introducere in type script
002. Introducere in type script002. Introducere in type script
002. Introducere in type scriptDmitrii Stoian
Ā 
C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abraha...
C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abraha...C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abraha...
C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abraha...yaevents
Ā 
Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Aaron Gustafson
Ā 
Whats New In C# 4 0 - NetPonto
Whats New In C# 4 0 - NetPontoWhats New In C# 4 0 - NetPonto
Whats New In C# 4 0 - NetPontoPaulo Morgado
Ā 
JavaScript 2016 for C# Developers
JavaScript 2016 for C# DevelopersJavaScript 2016 for C# Developers
JavaScript 2016 for C# DevelopersRick Beerendonk
Ā 
Beyond Java: ģžė°” 8ģ„ ģ¤‘ģ‹¬ģœ¼ė”œ ė³ø ģžė°”ģ˜ ķ˜ģ‹ 
Beyond Java: ģžė°” 8ģ„ ģ¤‘ģ‹¬ģœ¼ė”œ ė³ø ģžė°”ģ˜ ķ˜ģ‹ Beyond Java: ģžė°” 8ģ„ ģ¤‘ģ‹¬ģœ¼ė”œ ė³ø ģžė°”ģ˜ ķ˜ģ‹ 
Beyond Java: ģžė°” 8ģ„ ģ¤‘ģ‹¬ģœ¼ė”œ ė³ø ģžė°”ģ˜ ķ˜ģ‹ Sungchul Park
Ā 
C# Today and Tomorrow
C# Today and TomorrowC# Today and Tomorrow
C# Today and TomorrowBertrand Le Roy
Ā 
Java Performance MythBusters
Java Performance MythBustersJava Performance MythBusters
Java Performance MythBustersSebastian Zarnekow
Ā 
JavaScript introduction 1 ( Variables And Values )
JavaScript introduction 1 ( Variables And Values )JavaScript introduction 1 ( Variables And Values )
JavaScript introduction 1 ( Variables And Values )Victor Verhaagen
Ā 
What's New In C# 5.0 - Rumos InsideOut
What's New In C# 5.0 - Rumos InsideOutWhat's New In C# 5.0 - Rumos InsideOut
What's New In C# 5.0 - Rumos InsideOutPaulo Morgado
Ā 
Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)jewelyngrace
Ā 
Short intro to ECMAScript
Short intro to ECMAScriptShort intro to ECMAScript
Short intro to ECMAScriptJussi Pohjolainen
Ā 
Understanding JavaScript
Understanding JavaScriptUnderstanding JavaScript
Understanding JavaScriptnodejsbcn
Ā 
C# for Java Developers
C# for Java DevelopersC# for Java Developers
C# for Java DevelopersJussi Pohjolainen
Ā 
Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)Sumant Tambe
Ā 
Whatā€™s new in .NET
Whatā€™s new in .NETWhatā€™s new in .NET
Whatā€™s new in .NETDoommaker
Ā 

What's hot (19)

002. Introducere in type script
002. Introducere in type script002. Introducere in type script
002. Introducere in type script
Ā 
C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abraha...
C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abraha...C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abraha...
C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abraha...
Ā 
Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]
Ā 
Whats New In C# 4 0 - NetPonto
Whats New In C# 4 0 - NetPontoWhats New In C# 4 0 - NetPonto
Whats New In C# 4 0 - NetPonto
Ā 
JavaScript 2016 for C# Developers
JavaScript 2016 for C# DevelopersJavaScript 2016 for C# Developers
JavaScript 2016 for C# Developers
Ā 
Beyond Java: ģžė°” 8ģ„ ģ¤‘ģ‹¬ģœ¼ė”œ ė³ø ģžė°”ģ˜ ķ˜ģ‹ 
Beyond Java: ģžė°” 8ģ„ ģ¤‘ģ‹¬ģœ¼ė”œ ė³ø ģžė°”ģ˜ ķ˜ģ‹ Beyond Java: ģžė°” 8ģ„ ģ¤‘ģ‹¬ģœ¼ė”œ ė³ø ģžė°”ģ˜ ķ˜ģ‹ 
Beyond Java: ģžė°” 8ģ„ ģ¤‘ģ‹¬ģœ¼ė”œ ė³ø ģžė°”ģ˜ ķ˜ģ‹ 
Ā 
Day 1
Day 1Day 1
Day 1
Ā 
C# Today and Tomorrow
C# Today and TomorrowC# Today and Tomorrow
C# Today and Tomorrow
Ā 
Java Performance MythBusters
Java Performance MythBustersJava Performance MythBusters
Java Performance MythBusters
Ā 
JavaScript introduction 1 ( Variables And Values )
JavaScript introduction 1 ( Variables And Values )JavaScript introduction 1 ( Variables And Values )
JavaScript introduction 1 ( Variables And Values )
Ā 
What's New In C# 5.0 - Rumos InsideOut
What's New In C# 5.0 - Rumos InsideOutWhat's New In C# 5.0 - Rumos InsideOut
What's New In C# 5.0 - Rumos InsideOut
Ā 
Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)
Ā 
Short intro to ECMAScript
Short intro to ECMAScriptShort intro to ECMAScript
Short intro to ECMAScript
Ā 
Understanding JavaScript
Understanding JavaScriptUnderstanding JavaScript
Understanding JavaScript
Ā 
C# for Java Developers
C# for Java DevelopersC# for Java Developers
C# for Java Developers
Ā 
The Joy Of Ruby
The Joy Of RubyThe Joy Of Ruby
The Joy Of Ruby
Ā 
Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)
Ā 
Managed Compiler
Managed CompilerManaged Compiler
Managed Compiler
Ā 
Whatā€™s new in .NET
Whatā€™s new in .NETWhatā€™s new in .NET
Whatā€™s new in .NET
Ā 

Viewers also liked

Aprendendo a Aprender
Aprendendo a AprenderAprendendo a Aprender
Aprendendo a AprenderAlexandre Gomes
Ā 
Javascript orientado a testes
Javascript orientado a testesJavascript orientado a testes
Javascript orientado a testesAlexandre Gomes
Ā 
ProgramaĆ§Ć£o Funcional com Javascript
ProgramaĆ§Ć£o Funcional com JavascriptProgramaĆ§Ć£o Funcional com Javascript
ProgramaĆ§Ć£o Funcional com JavascriptAlexandre Gomes
Ā 
O Pensamento Ɓgil
O Pensamento ƁgilO Pensamento Ɓgil
O Pensamento ƁgilAlexandre Gomes
Ā 
Computacao Invisivel
Computacao InvisivelComputacao Invisivel
Computacao InvisivelAlexandre Gomes
Ā 
ConstruĆ§Ć£o de Software - 1Āŗ/2016
ConstruĆ§Ć£o de Software - 1Āŗ/2016ConstruĆ§Ć£o de Software - 1Āŗ/2016
ConstruĆ§Ć£o de Software - 1Āŗ/2016Alexandre Gomes
Ā 
OpenData, Web SemĆ¢ntica e afins.
OpenData, Web SemĆ¢ntica e afins.OpenData, Web SemĆ¢ntica e afins.
OpenData, Web SemĆ¢ntica e afins.Alexandre Gomes
Ā 

Viewers also liked (8)

Aprendendo a Aprender
Aprendendo a AprenderAprendendo a Aprender
Aprendendo a Aprender
Ā 
Javascript orientado a testes
Javascript orientado a testesJavascript orientado a testes
Javascript orientado a testes
Ā 
ProgramaĆ§Ć£o Funcional com Javascript
ProgramaĆ§Ć£o Funcional com JavascriptProgramaĆ§Ć£o Funcional com Javascript
ProgramaĆ§Ć£o Funcional com Javascript
Ā 
Business Modeling
Business ModelingBusiness Modeling
Business Modeling
Ā 
O Pensamento Ɓgil
O Pensamento ƁgilO Pensamento Ɓgil
O Pensamento Ɓgil
Ā 
Computacao Invisivel
Computacao InvisivelComputacao Invisivel
Computacao Invisivel
Ā 
ConstruĆ§Ć£o de Software - 1Āŗ/2016
ConstruĆ§Ć£o de Software - 1Āŗ/2016ConstruĆ§Ć£o de Software - 1Āŗ/2016
ConstruĆ§Ć£o de Software - 1Āŗ/2016
Ā 
OpenData, Web SemĆ¢ntica e afins.
OpenData, Web SemĆ¢ntica e afins.OpenData, Web SemĆ¢ntica e afins.
OpenData, Web SemĆ¢ntica e afins.
Ā 

Similar to Javascript do jeito certo

Introduction to ES6 with Tommy Cresine
Introduction to ES6 with Tommy CresineIntroduction to ES6 with Tommy Cresine
Introduction to ES6 with Tommy CresineMovel
Ā 
JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6Solution4Future
Ā 
Meta Object Protocols
Meta Object ProtocolsMeta Object Protocols
Meta Object ProtocolsPierre de Lacaze
Ā 
ECMA Script
ECMA ScriptECMA Script
ECMA ScriptNodeXperts
Ā 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to JavascriptAmit Tyagi
Ā 
Type script - advanced usage and practices
Type script  - advanced usage and practicesType script  - advanced usage and practices
Type script - advanced usage and practicesIwan van der Kleijn
Ā 
Rits Brown Bag - TypeScript
Rits Brown Bag - TypeScriptRits Brown Bag - TypeScript
Rits Brown Bag - TypeScriptRight IT Services
Ā 
Idiomatic Javascript (ES5 to ES2015+)
Idiomatic Javascript (ES5 to ES2015+)Idiomatic Javascript (ES5 to ES2015+)
Idiomatic Javascript (ES5 to ES2015+)David Atchley
Ā 
Javascript Basics
Javascript BasicsJavascript Basics
Javascript Basicsmsemenistyi
Ā 
JavaScript Editions ES7, ES8 and ES9 vs V8
JavaScript Editions ES7, ES8 and ES9 vs V8JavaScript Editions ES7, ES8 and ES9 vs V8
JavaScript Editions ES7, ES8 and ES9 vs V8Rafael Casuso Romate
Ā 
Groovy and Grails talk
Groovy and Grails talkGroovy and Grails talk
Groovy and Grails talkdesistartups
Ā 
Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Guillaume Laforge
Ā 
ECMAScript 6 Review
ECMAScript 6 ReviewECMAScript 6 Review
ECMAScript 6 ReviewSperasoft
Ā 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Troy Miles
Ā 
A few good JavaScript development tools
A few good JavaScript development toolsA few good JavaScript development tools
A few good JavaScript development toolsSimon Kim
Ā 
Ecmascript 2015 ā€“ best of new features()
Ecmascript 2015 ā€“ best of new features()Ecmascript 2015 ā€“ best of new features()
Ecmascript 2015 ā€“ best of new features()Miłosz Sobczak
Ā 
Javascript basics
Javascript basicsJavascript basics
Javascript basicsFin Chen
Ā 

Similar to Javascript do jeito certo (20)

Javascript status 2016
Javascript status 2016Javascript status 2016
Javascript status 2016
Ā 
Introduction to ES6 with Tommy Cresine
Introduction to ES6 with Tommy CresineIntroduction to ES6 with Tommy Cresine
Introduction to ES6 with Tommy Cresine
Ā 
JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6
Ā 
Meta Object Protocols
Meta Object ProtocolsMeta Object Protocols
Meta Object Protocols
Ā 
ECMA Script
ECMA ScriptECMA Script
ECMA Script
Ā 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
Ā 
Type script - advanced usage and practices
Type script  - advanced usage and practicesType script  - advanced usage and practices
Type script - advanced usage and practices
Ā 
Rits Brown Bag - TypeScript
Rits Brown Bag - TypeScriptRits Brown Bag - TypeScript
Rits Brown Bag - TypeScript
Ā 
Es6 to es5
Es6 to es5Es6 to es5
Es6 to es5
Ā 
JavaScript Core
JavaScript CoreJavaScript Core
JavaScript Core
Ā 
Idiomatic Javascript (ES5 to ES2015+)
Idiomatic Javascript (ES5 to ES2015+)Idiomatic Javascript (ES5 to ES2015+)
Idiomatic Javascript (ES5 to ES2015+)
Ā 
Javascript Basics
Javascript BasicsJavascript Basics
Javascript Basics
Ā 
JavaScript Editions ES7, ES8 and ES9 vs V8
JavaScript Editions ES7, ES8 and ES9 vs V8JavaScript Editions ES7, ES8 and ES9 vs V8
JavaScript Editions ES7, ES8 and ES9 vs V8
Ā 
Groovy and Grails talk
Groovy and Grails talkGroovy and Grails talk
Groovy and Grails talk
Ā 
Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007
Ā 
ECMAScript 6 Review
ECMAScript 6 ReviewECMAScript 6 Review
ECMAScript 6 Review
Ā 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1
Ā 
A few good JavaScript development tools
A few good JavaScript development toolsA few good JavaScript development tools
A few good JavaScript development tools
Ā 
Ecmascript 2015 ā€“ best of new features()
Ecmascript 2015 ā€“ best of new features()Ecmascript 2015 ā€“ best of new features()
Ecmascript 2015 ā€“ best of new features()
Ā 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
Ā 

More from Alexandre Gomes

ConstruĆ§Ć£o de Software - 1Āŗ/2017
ConstruĆ§Ć£o de Software - 1Āŗ/2017ConstruĆ§Ć£o de Software - 1Āŗ/2017
ConstruĆ§Ć£o de Software - 1Āŗ/2017Alexandre Gomes
Ā 
TDDing com Javascript
TDDing com JavascriptTDDing com Javascript
TDDing com JavascriptAlexandre Gomes
Ā 
UnB/PPCA/CS2016 - Projeto 2
UnB/PPCA/CS2016 - Projeto 2UnB/PPCA/CS2016 - Projeto 2
UnB/PPCA/CS2016 - Projeto 2Alexandre Gomes
Ā 
Plano de Ensino de TĆ³picos AvanƧados em Engenharia de Software
Plano de Ensino de TĆ³picos AvanƧados em Engenharia de SoftwarePlano de Ensino de TĆ³picos AvanƧados em Engenharia de Software
Plano de Ensino de TĆ³picos AvanƧados em Engenharia de SoftwareAlexandre Gomes
Ā 
ConstruĆ§Ć£o de Software - 1Āŗ semestre de 2014
ConstruĆ§Ć£o de Software - 1Āŗ semestre de 2014ConstruĆ§Ć£o de Software - 1Āŗ semestre de 2014
ConstruĆ§Ć£o de Software - 1Āŗ semestre de 2014Alexandre Gomes
Ā 
LaboratĆ³rio de MĆ©todos Ɓgeis 1/2014 - ApresentaĆ§Ć£o
LaboratĆ³rio de MĆ©todos Ɓgeis 1/2014 - ApresentaĆ§Ć£oLaboratĆ³rio de MĆ©todos Ɓgeis 1/2014 - ApresentaĆ§Ć£o
LaboratĆ³rio de MĆ©todos Ɓgeis 1/2014 - ApresentaĆ§Ć£oAlexandre Gomes
Ā 
Scraping by examples
Scraping by examplesScraping by examples
Scraping by examplesAlexandre Gomes
Ā 
Scraping by examples
Scraping by examplesScraping by examples
Scraping by examplesAlexandre Gomes
Ā 
Manifesto 2.0 para a Engenharia de Software
Manifesto 2.0 para a Engenharia de SoftwareManifesto 2.0 para a Engenharia de Software
Manifesto 2.0 para a Engenharia de SoftwareAlexandre Gomes
Ā 
Arquiteturas Orientadas a ServiƧos com a JBoss SOA Platform
Arquiteturas Orientadas a ServiƧos com a JBoss SOA PlatformArquiteturas Orientadas a ServiƧos com a JBoss SOA Platform
Arquiteturas Orientadas a ServiƧos com a JBoss SOA PlatformAlexandre Gomes
Ā 
Computacao Invisivel
Computacao InvisivelComputacao Invisivel
Computacao InvisivelAlexandre Gomes
Ā 

More from Alexandre Gomes (16)

ConstruĆ§Ć£o de Software - 1Āŗ/2017
ConstruĆ§Ć£o de Software - 1Āŗ/2017ConstruĆ§Ć£o de Software - 1Āŗ/2017
ConstruĆ§Ć£o de Software - 1Āŗ/2017
Ā 
TDDing com Javascript
TDDing com JavascriptTDDing com Javascript
TDDing com Javascript
Ā 
UnB/PPCA/CS2016 - Projeto 2
UnB/PPCA/CS2016 - Projeto 2UnB/PPCA/CS2016 - Projeto 2
UnB/PPCA/CS2016 - Projeto 2
Ā 
Plano de Ensino de TĆ³picos AvanƧados em Engenharia de Software
Plano de Ensino de TĆ³picos AvanƧados em Engenharia de SoftwarePlano de Ensino de TĆ³picos AvanƧados em Engenharia de Software
Plano de Ensino de TĆ³picos AvanƧados em Engenharia de Software
Ā 
Manifesto 2.0
Manifesto 2.0Manifesto 2.0
Manifesto 2.0
Ā 
ConstruĆ§Ć£o de Software - 1Āŗ semestre de 2014
ConstruĆ§Ć£o de Software - 1Āŗ semestre de 2014ConstruĆ§Ć£o de Software - 1Āŗ semestre de 2014
ConstruĆ§Ć£o de Software - 1Āŗ semestre de 2014
Ā 
Design Thinking
Design ThinkingDesign Thinking
Design Thinking
Ā 
Manifesto Ɓgil
Manifesto ƁgilManifesto Ɓgil
Manifesto Ɓgil
Ā 
LaboratĆ³rio de MĆ©todos Ɓgeis 1/2014 - ApresentaĆ§Ć£o
LaboratĆ³rio de MĆ©todos Ɓgeis 1/2014 - ApresentaĆ§Ć£oLaboratĆ³rio de MĆ©todos Ɓgeis 1/2014 - ApresentaĆ§Ć£o
LaboratĆ³rio de MĆ©todos Ɓgeis 1/2014 - ApresentaĆ§Ć£o
Ā 
Scraping by examples
Scraping by examplesScraping by examples
Scraping by examples
Ā 
Scraping by examples
Scraping by examplesScraping by examples
Scraping by examples
Ā 
Escolhas 2.0
Escolhas 2.0Escolhas 2.0
Escolhas 2.0
Ā 
Manifesto 2.0 para a Engenharia de Software
Manifesto 2.0 para a Engenharia de SoftwareManifesto 2.0 para a Engenharia de Software
Manifesto 2.0 para a Engenharia de Software
Ā 
Struts 2.x
Struts 2.xStruts 2.x
Struts 2.x
Ā 
Arquiteturas Orientadas a ServiƧos com a JBoss SOA Platform
Arquiteturas Orientadas a ServiƧos com a JBoss SOA PlatformArquiteturas Orientadas a ServiƧos com a JBoss SOA Platform
Arquiteturas Orientadas a ServiƧos com a JBoss SOA Platform
Ā 
Computacao Invisivel
Computacao InvisivelComputacao Invisivel
Computacao Invisivel
Ā 

Recently uploaded

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel AraĆŗjo
Ā 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
Ā 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
Ā 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
Ā 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
Ā 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
Ā 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
Ā 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
Ā 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
Ā 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
Ā 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
Ā 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
Ā 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
Ā 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
Ā 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
Ā 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
Ā 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
Ā 
Scaling API-first ā€“ The story of a global engineering organization
Scaling API-first ā€“ The story of a global engineering organizationScaling API-first ā€“ The story of a global engineering organization
Scaling API-first ā€“ The story of a global engineering organizationRadu Cotescu
Ā 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
Ā 

Recently uploaded (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Ā 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Ā 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
Ā 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
Ā 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
Ā 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Ā 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Ā 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
Ā 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Ā 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Ā 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
Ā 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
Ā 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
Ā 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
Ā 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
Ā 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
Ā 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Ā 
Scaling API-first ā€“ The story of a global engineering organization
Scaling API-first ā€“ The story of a global engineering organizationScaling API-first ā€“ The story of a global engineering organization
Scaling API-first ā€“ The story of a global engineering organization
Ā 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
Ā 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
Ā 

Javascript do jeito certo

  • 1. Javascript do jeito certo Alexandre Gomes
  • 2. javascript ? a que te remete o termo
  • 3. <form> <input type=button value="Close Window" onClick="javascript:window.close();"> </form>
  • 4. <script> function open_window(url) { mywin = window.open(url,"win",...); } </script> <body> <a href = "javascript:open_window('page1.html')"> <img src ="image.gif"> </a> <a href = "javascript:open_window('page2.html')"> <img src ="image.gif"> </a> </body>
  • 5. function validateForm() { var x = document.forms["myForm"]["fname"].value if (x == null || x == "") { alert("Nome obrigatĆ³rio!"); return false; } }
  • 6. para a grande maioria, javascript = magia negra
  • 7.
  • 8.
  • 9.
  • 11.
  • 12.
  • 15. javascript Aļ¬nal, Ć© do mal ou do bem?
  • 17. ISO IEC 16262 http://www.ecma-international.org/publications/standards/Ecma-262.htm
  • 18. ā€œ ECMAScript is an object-oriented programming language for performing computations and manipulating computational objects within a host environment. ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 19. ā€œ ECMAScript as deļ¬ned here is not intended to be computationally self- sufficient; indeed, there are no provisions in this speciļ¬cation for input of external data or output of computed results. ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 20. ā€œ Instead, it is expected that the computational environment (host environment) of an ECMAScript program will provide not only the objects and other facilities described in this speciļ¬cation but also certain environment-speciļ¬c host objects ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 21. ā€œ Some of the facilities of ECMAScript are similar to those used in other programming languages; in particular Java TM, Self, and Scheme ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 22. ā€œ A web browser provides an ECMAScript host environment for client-side computation including, for instance, objects that represent windows, menus, pop-ups, dialog boxes, text areas, anchors, frames, history, cookies, and input/output. navigator.appName; window.moveTo(100,100); ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 23. ā€œ Further, the host environment provides a means to attach scripting code to events such as change of focus, page and image loading, unloading, error and abort, selection, form submission, and mouse actions. <button type="button" onclick="displayDate()"> Display Date </button> ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 24. ā€œ The scripting code is reactive to user interaction and there is no need for a main program. <!-- Ate parece, mas nao e o ā€˜mainā€™ do javascript --> <script type="text/javascript"> function load() { alert("Page is loaded"); } </script> <body onload="load()"> ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 25. ā€œ A web server provides a different host environment for server-side computation including objects representing requests, clients, and ļ¬les; and mechanisms to lock and share data. ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 26. ā€œ Each Web browser and server that supports ECMAScript supplies its own host environment, completing the ECMAScript execution environment. ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 27. ā€œ ECMAScript is an object-oriented programming language (...) ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 28. ā€œ ECMAScript is an object-oriented programming language (...) Tipos Boolean, Number, String, Array, RegExp Operadores + - * / >> << >>> < > <= >= | & *= ^ ++ ComentĆ”rios // /* */ Estruturas do while for if else try catch switch ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 29. Tipos (construtores) Boolean Object Number Function String RegExp Array Date
  • 30. Tipos undeļ¬ned var x; alert(x); ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 31. Tipos null var x = null; alert(x); ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 32. Tipos Boolean var x = true; if(x) { alert('Verdadeiro'); } Obs: 0 e null equivalem a false ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 33. Tipos Number var x = 10; var y = 15; alert(x+y); var x = 10.1; var y = 15.2; alert(x+y); ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 34. Tipos String var x = ā€œAlexandreā€; alert(x); ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 35. Tipos Function var x = function() { alert("Alexandre"); }; x(); ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 36. > var x = true; > x.constructor; Boolean() > var x = "Alexandre"; > x.constructor; String() > var x = 3467; > x.constructor; Number() > var x = function() { alert("Alexandre"); }; > x.constructor; Function()
  • 37. var x = new Boolean(true); if(x) { alert('Verdadeiro'); } var x = new String(ā€œAlexandreā€); alert(x); var x = new Number(10); var y = new Number(15); alert(x+y);
  • 38. Operadores / <<= ? : delete % >>= = void >> == *= typeof << != /= ++ >>> === %= -- < !== += + > & -= - <= ^ >>>= ~ >= | &= ! instanceof && Ė†= * || in |=
  • 39. Operadores delete var a = 1 undeļ¬ned a 1 delete a true a ReferenceError: a is not deļ¬ned ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 40. Operadores typeof typeof 1 "number" typeof true "boolean" typeof "Alexandre" "string" typeof function() { alert('Oi') } "function" typeof null "object" ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 41. Operadores ++ e -- var a = 1 undeļ¬ned a++ 1 a 2 ++a 3 ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 42. Operadores instanceof var a = "alexandre" undeļ¬ned a instanceof String false var a = new String("alexandre") undeļ¬ned a instanceof String true a instanceof Object true ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 43. Operadores ==, !=, ===, !== 3 == "3" true 3 === "3" false 2 != "2" false 2 !== "2" true ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 44. Estruturas if/else continue switch do/while break throw while return try/catch for with debugger for/in
  • 45. Estruturas if/else var a = true if (a) { alert('Verdadeiro') } else { alert('Falso') } ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 46. Estruturas do/while var i = 1 do { alert(i); (...) i++; } while (i < 5) ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 47. Estruturas for for ( var i = 1; i < 5; i++) { alert(i); } (...) ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 48. Estruturas for/in var array = [1,3,5,7,9] for (var i in array) { alert(array[i]) } (...) ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 49. Estruturas for/each/in > var obj = { a: 1, b: 3, c: 5 } > obj.a 1 > for(p in obj) { alert(p + ": " + obj[p]) } > for each (v in obj) { alert(v) // v aqui igual ao obj[p] acima } ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 50. Estruturas with var obj = { a: 1, b: 3, c: 5 } alert(obj.a); // 1 alert(obj.b); // 3 alert(obj.c); // 5 with(obj) { alert(a); // 1 alert(b); // 3 alert(c); // 5 } ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 51. Estruturas switch/case var a = "alexandre"; switch (a) { case "sebastiao": alert("TiĆ£o?"); break; case "raimunda": alert("Raimundinha?"); break; case "alexandre": alert("AlĆŖ!"); break; } ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 52. ā€œ ECMAScript is object-based: basic language and host facilities are provided by objects, and an ECMAScript program is a cluster of communicating objects. ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 53. Numa aplicaĆ§Ć£o Javascript, coexistirĆ£o 3 grupos de objetos objetos deļ¬nidos pela objetos deļ¬nidos pelo objetos deļ¬nidos pelo especiļ¬caĆ§Ć£o web browser desenvolvedor ECMAScript Boolean window alexandre Number document mensagem String XMLHttpRequest ... Array ... ...
  • 54. ā€œ An ECMAScript object is a collection of properties each with zero or more attributes that determine how each property can be used alexandre nome: ā€œAlexandreā€ sobrenome: ā€œGomesā€ idade: 34 ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 55. ā€œ An ECMAScript object is a collection of properties each with zero or more attributes that determine how each property can be used alexandre nome: ā€œAlexandreā€ sobrenome: ā€œGomesā€ idade: 34 modiļ¬cĆ”vel: false ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 56. > var ale = new Object() > ale.nome = "Alexandre Gomes" "Alexandre Gomes" > ale.nascimento = new Date(1977,8,8) Thu Sep 08 1977 00:00:00 GMT-0300 (BRT) > ale.nome "Alexandre Gomes" > ale.nascimento Thu Sep 08 1977 00:00:00 GMT-0300 (BRT) > ale[ā€˜nomeā€™] "Alexandre Gomes" > ale[ā€˜nascimentoā€™] Thu Sep 08 1977 00:00:00 GMT-0300 (BRT)
  • 57. ā€œ Properties are containers (slots) that hold other objects, primitive values, or functions. alexandre nome: ā€œAlexandreā€ nascimento: new Date(1977,8,8,0,0,0,0) idade: function() { ... } ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 58. ā€œ ECMAScript deļ¬nes a collection of built-in objects Function, Array, String, Boolean, Number, Math, Date, RegExp, JSON Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError e URIError ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 59. > var x = "Alexandre"; > x.length String 9 > x.charAt(5); "n" > x + " Gomes" "Alexandre Gomes" > x.replace("dre", "dro"); "Alexandro" > x.big() "<big>Alexandre</big>" > x.link("http://alegom.es") "<a href="http://alegom.es">Alexandre</a>"
  • 60. Boolean >>> var x = true; >>> if(x) { alert('yes'); } else { alert('no') } // yes >>> !x false >>> x & false 0 >>> x && false false >>> x | false 1 >>> x || false true >>> var x = false; >>> if(x) { alert('yes'); } else { alert('no') } // no
  • 61. Number >>> var x = 10 >>> var y = 15; >>> z = x + y 25 >>> z.toFixed(2); "25.00" >>> z.toExponential(2); "2.50e+1" >>> 2.toExponential(2); SyntaxError: identifier starts immediately after numeric literal
  • 62. Math >>> Math.PI 3.141592653589793 >>> Math.sqrt(81); 9 >>> Math.tan(45); 1.6197751905438615 >>> Math.pow(3,2); 9 >>> Math.random(); 0.8528815588353642 >>> Math.random(); 0.955940929887219
  • 63. >>> var x = new Date(); Date >>> x.toString(); "Sun Apr 03 2011 12:20:42 GMT-0300 (BRT)" >>> x.getHours() + ":" + x.getMinutes() + ":" + x.getSeconds(); "12:20:42" >>> x.getDate() + "/" + x.getMonth() + "/" + x.getFullYear(); "3/3/2011" >>> var x = new Date("5/18/2006"); >>> x.toString(); "Thu May 18 2006 00:00:00 GMT-0300 (BRT)" >>> var x = new Date("2006-5-18"); >>> x.toString(); "Invalid Date" >>> var x = Date(2006,5,18,10,11,12,13); >>> x.toString(); "Sun Jun 18 2006 10:11:12 GMT-0300 (BRT)"
  • 64. >>> var x = new Date(); >>> x.toString(); Date "Sun Apr 03 2011 12:20:42 GMT-0300 (BRT)" >>> x.getHours() + ":" + x.getMinutes() + ":" + x.getSeconds(); "12:20:42" >>> x.getDate() + "/" + x.getMonth() + "/" + x.getFullYear(); "3/3/2011" >>> var x = new Date("5/18/2006"); >>> x.toString(); "Thu May 18 2006 00:00:00 GMT-0300 (BRT)" >>> var x = new Date("2006-5-18"); >>> x.toString(); "Invalid Date" >>> var x = Date(2006,5,18,10,11,12,13); >>> x.toString(); "Sun Jun 18 2006 10:11:12 GMT-0300 (BRT)"
  • 65. >>> var texto = "O gato roeu a roupa do rei de roma"; >>> var regex = new RegExp("gato", ā€œā€); >>> texto.match(regex); ["gato"] Regex >>> regex.exec(texto); ["gato"] >>> texto.match(/gato/); ["gato"] >>> texto.match(/O gato/); ["O gato"] >>> texto.match(/o gato/); null >>> texto.match(/o gato/i); ["O gato"] >>> texto.match(/o gato.*/i); ["O gato roeu a roupa do rei de roma"]
  • 66. >>> var obj = { "nome": "Alexandre", "idade" : "33" } >>> obj.constructor; Object() JSON >>> obj.nome "Alexandre" >>> obj.idade "33" >>> var msg = JSON.stringify(obj); >>> msg.constructor; String() >>> msg "{"nome":"Alexandre","idade":"33"}" >>> var msg = '{ "nome": "Alexandre", "idade" : "33" }' "{ "nome": "Alexandre", "idade" : "33" }" >>> msg.constructor; String() >>> msg.nome; undefined >>> obj = JSON.parse(msg); Object { nome="Alexandre", idade="33"} >>> obj.constructor; Object() >>> obj.nome; "Alexandre"
  • 67. var x = new Array(); >>> [] Array x[0] = "laranja" >>> ["laranja"] x[2] = "maĆ§Ć£" >>> ["laranja", undefined, "maĆ§Ć£"] x.length >>> 3 x.sort(); >>> ["laranja", "maĆ§Ć£", undefined] x.reverse(); >>> [undefined, "maĆ§Ć£", "laranja"] x = ["pera", "uva", new Date()] x.toString(); >>> "pera,uva,Sun Apr 03 2011 11:53:18 GMT-0300 (BRT
  • 68. ā€œ A web browser provides an ECMAScript host environment (...)
  • 69. > document.body 1. <body id=ā€‹"docs" class=ā€‹"section-docs en ltr yui-skin-sam PageDW- enDOMdocument js" role=ā€‹"document">ā€‹ā€¦ā€‹</body>ā€‹ > document.domain "developer.mozilla.org" > document.links [ <a href=ā€‹"#content-main">ā€‹Skip to the main contentā€‹</a>, <a href=ā€‹"#q">ā€‹Skip to the site searchā€‹</a>, <a href=ā€‹"/ā€‹">ā€‹ā€¦ā€‹</a>, <a href=ā€‹"/ā€‹index.php?" class=ā€‹"user-login">ā€‹Log inā€‹</a>, <a href=ā€‹"/ā€‹docs">ā€‹Doc Centerā€‹</a>, ā€¦
  • 70.
  • 71.
  • 72.
  • 73.
  • 74. { { Gecko Webkit
  • 75.
  • 76.
  • 77. e agora, prendam a respiraĆ§Ć£o...
  • 78. ā€œ apesar de ser OO, ECMAScript does not use classes such as those in C+ +, Smalltalk, or Java. ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 79. ā€œClassfulā€ ā€œClasslessā€ reuso por heranƧa de reuso por clonagem classes de objetos Pessoa joao nome nome: ā€œJoĆ£oā€ sexo idade: 28 <<herda>> <<clona>> FuncionĆ”ri maria o salĆ”rio nome: ā€œMariaā€ idade: 20
  • 80. ā€œClassfulā€ ā€œClasslessā€ modelagem modelagem top-down bottom-up primeiro a taxonomia e primeiro o seus relacionamentos... comportamento...
  • 81. ā€œClassfulā€ ā€œClasslessā€ objetos criados a objetos criados a partir de classes partir de clonagem... hoje = new Date() hoje = new Date() ...ou por ā€˜geraĆ§Ć£o expontĆ¢neaā€™ var x = { one: 1, two: 2 }
  • 82. ā€œClassfulā€ ā€œClasslessā€ objetos carregam a objetos carregam as estrutura e o caracterĆ­sticas de comportamento de sua classe seu protĆ³tipo
  • 83. ProgramaĆ§Ć£o baseada em protĆ³tipos protĆ³tipo
  • 84. ProgramaĆ§Ć£o baseada em protĆ³tipos protĆ³tipo clone
  • 85. ProgramaĆ§Ć£o baseada em protĆ³tipos protĆ³tipo clone
  • 86. ProgramaĆ§Ć£o baseada em protĆ³tipos >>> var conta = { saldo: 1000.00 }; >>> conta.saldo 1000 >>> conta.limite undefined >>> var conta_especial = { limite: 500.00 } >>> conta_especial.limite 500 >>> conta_especial.saldo undefined >>> conta_especial.__proto__ = conta // referĆŖncia explĆ­cita Object { saldo=1000} >>> conta_especial.saldo 1000
  • 87. HeranƧa baseada em protĆ³tipos > var conta = function(saldo) { this.saldo = saldo; this.ver_saldo = function() { alert('saldo = ' + this.saldo) } } > c1 = new conta(1000) > c1.ver_saldo() > var conta_especial = function(saldo, limite) { this.inheritFrom = conta; this.inheritFrom(); this.saldo = saldo; this.limite = limite; } > c2 = new conta_especial(2000,3000) > c2.ver_saldo()
  • 88. ā€œ objects may be created in various ways including via a literal notation var conta = { saldo: 1000.00 } ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 89. ā€œ objects may be created in various ways including via a literal notation var conta = { saldo: 1000.00 } or via constructors hoje = new Date() ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 90. ā€œ Each constructor is a function hoje = new Date() function Date() { ... } ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 91. mas function Ć© tambĆ©m um objeto Date() var Date = function() { ... } hoje = new Date()
  • 92. construtor function Date() objeto
  • 93. construtor function Date() objeto propriedades
  • 94. ā€œ Each constructor is a function that has a property named ā€œprototypeā€ that is used to implement prototype-based inheritance and shared properties. ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 95. ā€œ Each constructor is a function that has a property named ā€œprototypeā€(...) Date() <<construtor prototype ProtĆ³tipo do Date() ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 96. Date() <<construtor prototype ProtĆ³tipo do Date() ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 97. ā€œ Every object created by a constructor Date() <<construtor hoje = new Date() hoje prototype ProtĆ³tipo do Date() ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 98. ā€œ Every object created by a constructor has an implicit reference (called the objectā€™s prototype) Date() <<construtor hoje = new Date() hoje prototype prototype ProtĆ³tipo do Date() ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 99. ā€œ Every object created by a constructor has an implicit reference (called the objectā€™s prototype) to the value of its constructorā€™s ā€œprototypeā€ property. Date() <<construtor hoje = new Date() hoje prototype prototype ProtĆ³tipo do Date() ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 100. ā€œ Furthermore, a prototype may have a non-null implicit reference to its prototype, and so on; this is called the prototype chain. Date() <<construtor ProtĆ³tipo do Date() ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 101. ā€œ Furthermore, a prototype may have a non-null implicit reference to its prototype, and so on; this is called the prototype chain. Date() <<construtor ProtĆ³tipo do protĆ³tipo do Date() ProtĆ³tipo do ProtĆ³tipo protĆ³tipo do do Date() protĆ³tipo do Date() ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 102. ā€œ When a reference is made to a property in an object, that reference is to the property of that name in the ļ¬rst object in the prototype chain that contains a property of that name. ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 103. ā€œ When a reference is made to a property in an object, that reference is to the property of that name in the ļ¬rst object in the prototype chain that contains a property of that name. obj p3: p1: ā€œumā€ ā€œtresā€ p2: p4: ā€œdoisā€ ā€œquatroā€ ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 104. ā€œ When a reference is made to a property in an object, that reference is to the property of that name in the ļ¬rst object in the prototype chain that contains a property of that name. obj obj.p1 p3: p1: ā€œumā€ ā€œtresā€ p2: p4: ā€œdoisā€ ā€œquatroā€ ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 105. ā€œ When a reference is made to a property in an object, that reference is to the property of that name in the ļ¬rst object in the prototype chain that contains a property of that name. obj obj.p1 p3: p1: ā€œumā€ ā€œtresā€ obj.p2 p2: p4: ā€œdoisā€ ā€œquatroā€ ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 106. ā€œ When a reference is made to a property in an object, that reference is to the property of that name in the ļ¬rst object in the prototype chain that contains a property of that name. obj obj.p1 p3: p1: ā€œumā€ ā€œtresā€ obj.p2 obj.p3 p2: p4: ā€œdoisā€ ā€œquatroā€ ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 107. ā€œ When a reference is made to a property in an object, that reference is to the property of that name in the ļ¬rst object in the prototype chain that contains a property of that name. obj obj.p1 p3: p1: ā€œumā€ ā€œtresā€ obj.p2 obj.p3 p2: p4: obj.p4 ā€œdoisā€ ā€œquatroā€ ECMAScript Language Speciļ¬cation 5th edition (December 2009)
  • 108. > var Pessoa = function(nome, idade) { this.nome = nome; this.idade = idade; } > var alexandre = new Pessoa('Ale', 33); > alexandre.nome "Ale" > alexandre.idade 33 > var sebastiana = new Pessoa('Sebastiana', 88); > sebastiana.nome "Sebastiana" > sebastiana.idade 88
  • 109. > var Pessoa = function(nome, idade) { this.nome = nome; this.idade = idade; } construtor > var alexandre = new Pessoa('Ale', 33); > alexandre.nome "Ale" > alexandre.idade 33 > var sebastiana = new Pessoa('Sebastiana', 88); > sebastiana.nome "Sebastiana" > sebastiana.idade 88
  • 110. > var Pessoa = function(nome, idade) { this.nome = nome; this.idade = idade; } > var alexandre = new Pessoa('Ale', 33); > alexandre.nome "Ale" > alexandre.idade 33 objeto 1 > var sebastiana = new Pessoa('Sebastiana', 88); > sebastiana.nome "Sebastiana" > sebastiana.idade 88
  • 111. > var Pessoa = function(nome, idade) { this.nome = nome; this.idade = idade; } > var alexandre = new Pessoa('Ale', 33); > alexandre.nome "Ale" > alexandre.idade 33 > var sebastiana = new Pessoa('Sebastiana', 88); > sebastiana.nome "Sebastiana" > sebastiana.idade 88 objeto 2
  • 112. Pessoa() <<construtor> nome idade
  • 113. ProtĆ³tipo do Pessoa() Pessoa() <<construtor> nome idade
  • 114. ProtĆ³tipo do Pessoa() Pessoa() <<construtor> nome idade alexandre sebastiana nome = ā€˜Aleā€™ nome = ā€˜Seb...ā€™ idade = 33 idade = 88
  • 115. ProtĆ³tipo do Pessoa() ? > alexandre.nome Pessoa() <<construtor> nome idade alexandre sebastiana nome = ā€˜Aleā€™ nome = ā€˜Seb...ā€™ idade = 33 idade = 88
  • 116. ProtĆ³tipo do > alexandre.nome Pessoa() ā€œAleā€ Pessoa() <<construtor> nome idade alexandre sebastiana nome = ā€˜Aleā€™ nome = ā€˜Seb...ā€™ idade = 33 idade = 88
  • 117. ProtĆ³tipo do > alexandre.nome Pessoa() ā€œAleā€ > sebastiana.idade 88 Pessoa() <<construtor> nome idade alexandre sebastiana nome = ā€˜Aleā€™ nome = ā€˜Seb...ā€™ idade = 33 idade = 88
  • 118. ProtĆ³tipo do > alexandre.nome Pessoa() ā€œAleā€ > sebastiana.idade 88 Pessoa() ? <<construtor> > alexandre.sexo nome idade alexandre sebastiana nome = ā€˜Aleā€™ nome = ā€˜Seb...ā€™ idade = 33 idade = 88
  • 119. ProtĆ³tipo do > alexandre.nome Pessoa() ā€œAleā€ > sebastiana.idade 88 Pessoa() <<construtor> > alexandre.sexo nome undefined idade alexandre sebastiana nome = ā€˜Aleā€™ nome = ā€˜Seb...ā€™ idade = 33 idade = 88
  • 120. ProtĆ³tipo do > alexandre.nome Pessoa() ā€œAleā€ > sebastiana.idade 88 Pessoa() <<construtor> > alexandre.sexo nome undefined idade > sebastiana.sexo undefined alexandre sebastiana nome = ā€˜Aleā€™ nome = ā€˜Seb...ā€™ idade = 33 idade = 88
  • 121. ProtĆ³tipo Pessoa() <<construtor> nome idade alexandre sebastiana nome = ā€˜Aleā€™ nome = ā€˜Seb...ā€™ idade = 33 idade = 88
  • 122. ProtĆ³tipo > Pessoa.prototype.sexo = ā€œMā€ sexo Pessoa() <<construtor> nome idade alexandre sebastiana nome = ā€˜Aleā€™ nome = ā€˜Seb...ā€™ idade = 33 idade = 88
  • 123. ProtĆ³tipo > Pessoa.prototype.sexo = ā€œMā€ sexo > alexandre.sexo ā€œMā€ Pessoa() <<construtor> nome idade alexandre sebastiana nome = ā€˜Aleā€™ nome = ā€˜Seb...ā€™ idade = 33 idade = 88
  • 124. ProtĆ³tipo > Pessoa.prototype.sexo = ā€œMā€ sexo > alexandre.sexo ā€œMā€ > sebastiana.sexo ā€œMā€ Pessoa() <<construtor> nome idade alexandre sebastiana nome = ā€˜Aleā€™ nome = ā€˜Seb...ā€™ idade = 33 idade = 88
  • 125. ProtĆ³tipo > Pessoa.prototype.sexo = ā€œMā€ sexo > alexandre.sexo ā€œMā€ > sebastiana.sexo ā€œMā€ Pessoa() <<construtor> nome > sebastiana.sexo = ā€œFā€ idade alexandre sebastiana nome = ā€˜Aleā€™ nome = ā€˜Seb...ā€™ idade = 33 idade = 88
  • 126. ProtĆ³tipo > Pessoa.prototype.sexo = ā€œMā€ sexo > alexandre.sexo ā€œMā€ > sebastiana.sexo ā€œMā€ Pessoa() <<construtor> nome > sebastiana.sexo = ā€œFā€ idade > sebastiana.sexo ā€œFā€ alexandre sebastiana nome = ā€˜Aleā€™ nome = ā€˜Seb...ā€™ idade = 33 idade = 88
  • 127. Object
  • 128. Object Prototipo de Object
  • 129. Object Prototipo de Object Object.prototype.pO = 1
  • 130. Object Prototipo de Object pO = 1 Object.prototype.pO = 1
  • 131. Object Prototipo de Object pO = 1 A a=2 var A = function() { this.a = 2; }
  • 132. Object Prototipo de Object pO = 1 A Prototipo de A a=2
  • 133. Object Prototipo de Object pO = 1 A Prototipo de A a=2 pA = 3 A.prototype.pA = 3
  • 134. Object Prototipo de Object pO = 1 A Prototipo de A a=2 pA = 3 B var B = function() { this.b = 4; b=4 }
  • 135. Object Prototipo de Object pO = 1 A Prototipo de A a=2 pA = 3 B Prototipo de B b=4
  • 136. Object Prototipo de Object B.prototype = new A pO = 1 A Prototipo de A a=2 pA = 3 B Prototipo de B b=4
  • 137. Object Prototipo de Object B.prototype = new A pO = 1 A Prototipo de A a=2 pA = 3 B new A() b=4
  • 138. Object Prototipo de Object B.prototype.pB = 5 pO = 1 A Prototipo de A a=2 pA = 3 B new A() b=4 pB = 5
  • 139. Object Prototipo de Object pO = 1 A Prototipo de A a=2 pA = 3 B new A() b=4 pB = 5
  • 140. Object Prototipo de Object x = new= 1 pO B() A Prototipo de A a=2 pA = 3 B new A() X b=4 pB = 5
  • 141. Object Prototipo de Object pO = 1 A Prototipo de A a=2 pA = 3 B new A() X b=4 pB = 5
  • 142. Object Prototipo de Object pO = 1 A Prototipo de A a=2 pA = 3 x.pB ? B new A() X b=4 pB = 5
  • 143. Object Prototipo de Object pO = 1 A Prototipo de A a=2 pA = 3 x.b B new A() X b=4 pB = 5
  • 144. Object Prototipo de Object pO = 1 A Prototipo de A a=2 pA = 3 x.b ? B new A() X b=4 pB = 5
  • 145. Object Prototipo de Object pO = 1 A Prototipo de A a=2 pA = 3 x.pA B new A() X b=4 pB = 5
  • 146. Object Prototipo de Object pO = 1 A Prototipo de A a=2 pA = 3 x.pA ? B new A() X b=4 pB = 5
  • 147. Object Prototipo de Object pO = 1 A Prototipo de A a=2 pA = 3 x.a B new A() X b=4 pB = 5
  • 148. Object Prototipo de Object pO = 1 A Prototipo de A a=2 pA = 3 x.a ? B new A() X b=4 pB = 5
  • 149. Object Prototipo de Object pO = 1 A Prototipo de A a=2 pA = 3 x.pO B new A() X b=4 pB = 5
  • 150. Object Prototipo de Object pO = 1 A Prototipo de A a=2 pA = 3 x.pO ? B new A() X b=4 pB = 5
  • 151. @see http://www.w3schools.com/js/default.asp https://developer.mozilla.org/en/JavaScript/Reference https://developer.mozilla.org/en/Gecko_DOM_Reference http://developer.apple.com/library/safari/#documentation/ AppleApplications/Reference/WebKitDOMRef/index.html
  • 152. o que tem sido feito com javascript
  • 154.
  • 155.
  • 156.
  • 157. http://plugins.jquery.com/ ā€¢ Ajax ā€¢ Layout ā€¢ Animation and Effects ā€¢ Media ā€¢ Browser Tweaks ā€¢ Menus ā€¢ Data ā€¢ Metaplugin ā€¢ DOM ā€¢ Navigation ā€¢ Drag-and-Drop ā€¢ Tables ā€¢ Events ā€¢ User Interface ā€¢ Forms ā€¢ Utilities ā€¢ Integration ā€¢ Widgets ā€¢ JavaScript ā€¢ Windows and Overlays ā€¢ jQuery Extensions
  • 162.
  • 163. Node's goal is to provide an easy way to build scalable network programs. http://nodejs.org/
  • 164.
  • 165.
  • 166.
  • 167.
  • 168. Backbone supplies structure to JavaScript-heavy applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing application over a RESTful JSON interface. http://documentcloud.github.com/backbone/
  • 169. CoffeeScript is a little language that compiles into JavaScript. (...) CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way. http://jashkenas.github.com/coffee-script/
  • 170. if (opposite) { number = -42; } number = -42 if opposite
  • 171. square = function(x) { return x * x; }; square = (x) -> x * x
  • 172. cubes = (function() { var _i, _len, _results; _results = []; for (_i = 0, _len = list.length; _i < _len; _i++) { num = list[_i]; _results.push(math.cube(num)); } return _results; })(); cubes = (math.cube num for num in list)
  • 173. P&R

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. Mas a&amp;#xED; chegou o Google e lan&amp;#xE7;ou sua ferramenta de webmail, em meio a um mercado aparentemente saturado.\n
  8. ...popularizou uma t&amp;#xE9;cnica\n
  9. E mudou a percep&amp;#xE7;&amp;#xE3;o que o mundo tinha da tecnologia.\n
  10. \n
  11. Javascript &amp;#xE9; 3&amp;#xAA; tecnologia com mais projetos no Github\n
  12. ...e &amp;#xE9; a tecnologia que tem a maior base de c&amp;#xF3;digo!\n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. At&amp;#xE9; mesmo diferentes vers&amp;#xF5;es de browser prov&amp;#xEA;em diferentes hosts environments.\n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \\\n
  50. \\\n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n
  72. \n
  73. \n
  74. \n
  75. \n
  76. \n
  77. \n
  78. O fato &amp;#xE9; que....\n
  79. \n
  80. \n
  81. \n
  82. \n
  83. \n
  84. \n
  85. \n
  86. \n
  87. \n
  88. \n
  89. \n
  90. \n
  91. \n
  92. \n
  93. \n
  94. \n
  95. \n
  96. \n
  97. \n
  98. \n
  99. \n
  100. \n
  101. \n
  102. \n
  103. \n
  104. \n
  105. \n
  106. \n
  107. \n
  108. \n
  109. \n
  110. \n
  111. \n
  112. \n
  113. \n
  114. \n
  115. \n
  116. \n
  117. \n
  118. \n
  119. \n
  120. \n
  121. \n
  122. \n
  123. \n
  124. \n
  125. \n
  126. \n
  127. \n
  128. \n
  129. \n
  130. \n
  131. \n
  132. \n
  133. \n
  134. \n
  135. \n
  136. \n
  137. \n
  138. \n
  139. \n
  140. \n
  141. \n
  142. \n
  143. \n
  144. \n
  145. \n
  146. \n
  147. \n
  148. \n
  149. \n
  150. \n
  151. \n
  152. \n
  153. \n
  154. \n
  155. \n
  156. \n
  157. \n
  158. \n
  159. \n
  160. \n
  161. \n
  162. \n
  163. \n
  164. \n
  165. \n
  166. \n
  167. \n
  168. \n
  169. \n
  170. \n
  171. \n
  172. \n
  173. \n
  174. \n
  175. \n
  176. \n
  177. \n
  178. \n
  179. \n
  180. \n
  181. \n
  182. \n
  183. \n
  184. \n
  185. \n
  186. \n
  187. \n
  188. \n
  189. \n
  190. \n
  191. \n
  192. \n
  193. \n
  194. \n
  195. \n
  196. \n
  197. \n
  198. \n
  199. \n
  200. \n
  201. \n
  202. \n
  203. \n
  204. \n
  205. \n
  206. \n
  207. \n
  208. TODO\n- Subclasse com chamada a A.call(this) no construtor\n