Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Porque usar JS para desenvolver solução de economia de energia em dispositivos moveis

Porque usar JS para desenvolver solução de economia de energia em dispositivos moveis

Uma apresentação simples para mostra no projeto que eu estou o porque usar JavaScript para desenvolver a solução para economizar energia.
Uma apresentação simples, apenas para esclarecer alguns pontos de forma rápida, ou seja, ela não é bem feita nem esclarecedora.

Psycho Mantys

April 03, 2013
Tweet

More Decks by Psycho Mantys

Other Decks in Programming

Transcript

  1. Porque usar? Suporte a Annotations Serializa¸ c˜ ao Reflex˜ ao

    Porque usar javascript para desenvolver solu¸ c˜ ao de economia de energia em dispositivos moveis Baltazar Tavares Vanderlei Instituto de Computa¸ c˜ ao - IC/UFAL 4 de abril de 2013
  2. Porque usar? Suporte a Annotations Serializa¸ c˜ ao Reflex˜ ao

    Sum´ ario 1 Porque usar? 2 Suporte a Annotations 3 Serializa¸ c˜ ao 4 Reflex˜ ao
  3. Porque usar? Suporte a Annotations Serializa¸ c˜ ao Reflex˜ ao

    Sum´ ario 1 Porque usar? 2 Suporte a Annotations 3 Serializa¸ c˜ ao 4 Reflex˜ ao
  4. Porque usar? Suporte a Annotations Serializa¸ c˜ ao Reflex˜ ao

    Linguagem moderna O mais portavel das alternativas Suporta Annotations Serializa¸ c˜ ao Reflex˜ ao Sobrescrever fun¸ c˜ oes
  5. Porque usar? Suporte a Annotations Serializa¸ c˜ ao Reflex˜ ao

    Sum´ ario 1 Porque usar? 2 Suporte a Annotations 3 Serializa¸ c˜ ao 4 Reflex˜ ao
  6. Porque usar? Suporte a Annotations Serializa¸ c˜ ao Reflex˜ ao

    Na verdade... N˜ ao tem Mas existe como contornar Fazer na m˜ ao(a seguir...) Declarar em um espa¸ co de nomes conhecido Object.defineProperty(obj, propname, desc)
  7. Porque usar? Suporte a Annotations Serializa¸ c˜ ao Reflex˜ ao

    f u n c t i o n Human(){ /∗ @@−FirstName− ∗ myType :TEXT, ∗ myDefaultValue : John ∗ @@ ∗/ t h i s . FirstName ; /∗ @@−LastName− ∗ myType :TEXT, ∗ myDefaultValue : Doe ∗ @@ ∗/ t h i s . LastName ; t h i s . t o S t r i n g = f u n c t i o n (){ r e t u r n t h i s . FirstName+” ”+ t h i s . LastName ; } }
  8. Porque usar? Suporte a Annotations Serializa¸ c˜ ao Reflex˜ ao

    var h = new Human ( ) ; console . log ( Annotations (Human ) ) ; h . FirstName = Annotations (Human ) [ ’ FirstName ’ ] [ ’ myDefault h . LastName = Annotations (Human ) . LastName . myDefaultValue ; console . log (h . t o S t r i n g ( ) ) ; /∗ d i s p l a y John Doe∗/
  9. Porque usar? Suporte a Annotations Serializa¸ c˜ ao Reflex˜ ao

    Sum´ ario 1 Porque usar? 2 Suporte a Annotations 3 Serializa¸ c˜ ao 4 Reflex˜ ao
  10. Porque usar? Suporte a Annotations Serializa¸ c˜ ao Reflex˜ ao

    Disponivel com JSON Se n˜ ao disponovel, pode usar implementa¸ c˜ ao propria http://www.sitepoint.com/javascript-json-serialization/ https://github.com/douglascrockford/JSON-js
  11. Porque usar? Suporte a Annotations Serializa¸ c˜ ao Reflex˜ ao

    var obj1 = { b1 : true , s1 : ” t e x t s t r i n g ” , n1 : 12345 , n2 : null , n3 : undefined , a1 : [ 1 ,1 ,2 ,3 ,5 ,8 , [13 , 21 , 34] ] , o1 : { a : [3 , 2 , 1] , b : { c : 42 , d : [ 3.14 , 1.618 ] } } };
  12. Porque usar? Suporte a Annotations Serializa¸ c˜ ao Reflex˜ ao

    // JSON s t r i n g i f y var json = JSON. s t r i n g i f y ( obj1 ) ; // JSON parse var obj2 = JSON. parse ( json ) ;
  13. Porque usar? Suporte a Annotations Serializa¸ c˜ ao Reflex˜ ao

    Sum´ ario 1 Porque usar? 2 Suporte a Annotations 3 Serializa¸ c˜ ao 4 Reflex˜ ao
  14. Porque usar? Suporte a Annotations Serializa¸ c˜ ao Reflex˜ ao

    Object.getOwnPropertyNames(obj) Object.getOwnPropertyDescriptor(obj, ”prop”)
  15. Porque usar? Suporte a Annotations Serializa¸ c˜ ao Reflex˜ ao

    > var obj = { prop : ”abc ” , method : f u n c t i o n ( x , y , z ) {} }; > Object . getOwnPropertyNames ( obj ) [ ’ prop ’ , ’ method ’ ]
  16. Porque usar? Suporte a Annotations Serializa¸ c˜ ao Reflex˜ ao

    > Object . getOwnPropertyDescriptor ( obj , ” prop ”) { value : ’ abc ’ , w r i t a b l e : true , enumerable : true , c o n f i g u r a b l e : true }
  17. Porque usar? Suporte a Annotations Serializa¸ c˜ ao Reflex˜ ao

    > Object . getOwnPropertyDescriptor ( obj , ”method ”) { value : [ Function ] , w r i t a b l e : true , enumerable : true , c o n f i g u r a b l e : true }
  18. Porque usar? Suporte a Annotations Serializa¸ c˜ ao Reflex˜ ao

    Extraind argumento de func˜ oes f u n c t i o n argumentNames ( fun ) { var names = fun . t o S t r i n g ( ) . match (/ˆ[\ s \(]∗ f u n c t i o . r e p l a c e (/\/\/.∗?[\ r \n ] | \ / \ ∗ ( ? : . | [ \ r \n ])∗ . r e p l a c e (/\ s+/g , ’ ’ ) . s p l i t ( ’ , ’ ) ; r e t u r n names . length == 1 && ! names [ 0 ] ? [ ] : nam } f u n c t i o n foo ( bar , baz ) {} argumentNames ( foo )
  19. Porque usar? Suporte a Annotations Serializa¸ c˜ ao Reflex˜ ao

    Objeto proxy var obj = { noSuchMethod : f u n c t i o n (name , args ) { p r i n t (” Method ” + name ) ; } }; obj . foo ( ) ;
  20. Porque usar? Suporte a Annotations Serializa¸ c˜ ao Reflex˜ ao

    Getters e Setters var obj = { get foo () { r e t u r n ” g e t t e r ”; } , s e t foo ( value ) { p r i n t (” s e t t e r : ”+value ) ; } };
  21. Porque usar? Suporte a Annotations Serializa¸ c˜ ao Reflex˜ ao

    > obj . foo g e t t e r > obj . foo = ” bla ”; s e t t e r : bla bla > Object . getOwnPropertyDescriptor ( obj , ” foo ”) { get : [ Function : foo ] , s e t : [ Function : foo ] , enumerable : true , c o n f i g u r a b l e : true }