SlideShare a Scribd company logo
Não alimente os trolls:
Javascript é bonito!
@rafael_sps
Quem?
Tecnólogo em Telecomunicações IFSul
Rafael Specht da Silva
Javascript
até que é
bonito!
@rafael_sps
Javascript é
bonito legal!
@rafael_sps
“Se JavaScript não fosse tão
feia, um livro chamado
‘JavaScript: The Good Parts’
não seria o best-seller da
linguagem na Amazon”
http://simpleprogrammer.com/2013/05/06/why-javascript-is-doomed/
Inconsistente
typeof {} // ‘object’
typeof [] // ‘object’
typeof null // ‘object’
typeof undefined // ‘undefined’
undefined == null // true
+
var n1 = 2;
var n2 = 3;
n1 + n2 // 5
var n1 = 2
var n2 = ‘3’
n1 + n2 // ‘23’
https://twitter.com/1Marc/status/486803289175232512
== e ===
0 == false // true
0 === false // false
1 == true // true
1 === true // false
var url1 = 'http://localhost/rs/santa-maria'
var url2 = 'http://localhost/'
var getState = function (url) {
var stateMatch = url.match(//[a-z]{2}//gi);
var state = null;
if (stateMatch !== null && stateMatch.length > 0) {
state = stateMatch[0].replace(///g, '');
}
return state;
}
getState(url1); // ‘rs’
getState(url2); // null
“Se você trata null e
undefined igualmente, é
recompensado com
comparações mais simples”
https://speakerdeck.com/getify/new-rules-for-javascript
if (stateMatch !== null && stateMatch.length > 0) {
state = stateMatch[0].replace(///g, '');
}
if (stateMatch && stateMatch.length) {
state = stateMatch[0].replace(///g, '');
}
var data = {name: 'Luke', surname: 'Skywalker'}
var User = function (name, surname) {
this.name = name;
this.surname = surname;
this.getCompleteName = function () {
return this.name + ' ' + this.surname;
}
}
var user = new User(data.name, data.surname)
user.getCompleteName(); // 'Luke Skywalker'
var data = {name: 'Luke'}
var user = new User(data.name, data.surname)
user.getCompleteName(); // 'Luke undefined'
var data = {name: 'Luke'}
var User = function (name, surname) {
this.name = name;
this.surname = surname || '';
this.getCompleteName = function () {
return this.name + ' ' + this.surname;
}
}
var user = new User(data.name, data.surname)
user.getCompleteName(); // 'Luke '
this
var UserView = function () {
function setName (name) {
this.name = name;
}
function setEvents () {
var that = this;
$('.hit').on('click', function () {
console.log(this); // <button class="hit">Hit me!</button>
$(this).toggleClass('odd');
that.setName($('.name').val());
});
}
return {
setEvents: setEvents,
setName: setName
}
}
function setEvents () {
var that = this;
$('.hit').on('click', function () {
console.log(this);
$(this).toggleClass('odd');
that.setName($('.name').val());
});
}
function setEvents () {
var button = $('.hit');
function handler () {
console.log(this);
button.toggleClass('odd');
this.setName($('.name').val());
}
button.on('click', handler.bind(this));
}
https://github.com/rssilva/presentations/blob/master/front-in-sm-2015/thisWorld/ex1.html
var Human = {
setName: function (name) {
console.log(this);
this.name = name;
},
sayHi: function () {
return 'Hi! My name is ' + this.name + '!';
}
}
var Ninja = {
setName: Human.setName,
setStealhLevel: function (level) {
console.log(this)
this.stealthLevel = level;
}
}
var Turtle = {
setHullLevel: function (level) {
console.log(this);
this.hullLevel = level;
}
}
var NinjaTurtle = {
setName: Ninja.setName,
setStealhLevel: Ninja.setStealhLevel,
setHullLevel: Turtle.setHullLevel
}
var raphael = Object.create(NinjaTurtle, {});
raphael.setName('Raphael');
raphael.setStealhLevel(50);
raphael.setHullLevel(100);
console.log(raphael);
console.log(raphael.sayHi);
https://github.com/rssilva/presentations/blob/master/front-in-sm-2015/thisWorld/ex2.html
Objetos
mantém
referência
var a = [1, 2, 3];
var b = a;
b.pop();
console.log(a); // [1, 2]
console.log(b); // [1, 2]
MODAIS
https://github.com/rssilva/presentations/tree/master/front-in-sm-
2015/objectsByReference
É importante:
- ter bom-humor!
- criticar construtivamente
- aprender os paradigmas
Toda linguagem tem
peculiaridades. Aprender
a lidar com elas é parte do
nosso trabalho.
Obrigado!
github.com/rssilva
twitter.com/rafael_sps
speakerdeck.com/rssilva

More Related Content

What's hot

MVest Spring Job Execution
MVest Spring Job ExecutionMVest Spring Job Execution
MVest Spring Job ExecutionShraddha Bora
 
XQDT - XQuery Getting Momentum in Eclipse
XQDT - XQuery Getting Momentum in EclipseXQDT - XQuery Getting Momentum in Eclipse
XQDT - XQuery Getting Momentum in Eclipse
guesteb3ec2
 
Couchdb
CouchdbCouchdb
Couchdb
Brian Smith
 
AngularJS Services
AngularJS ServicesAngularJS Services
AngularJS Services
Eyal Vardi
 
AngularJS Routing
AngularJS RoutingAngularJS Routing
AngularJS Routing
Eyal Vardi
 
Growing jQuery
Growing jQueryGrowing jQuery
Growing jQuery
gueste8d8bc
 
Sins Against Drupal 2
Sins Against Drupal 2Sins Against Drupal 2
Sins Against Drupal 2
Aaron Crosman
 
AngulrJS Overview
AngulrJS OverviewAngulrJS Overview
AngulrJS Overview
Eyal Vardi
 
WordPress Kitchen 2014 - Александр Стриха: Кеширование в WordPress
WordPress Kitchen 2014 - Александр Стриха: Кеширование в WordPress WordPress Kitchen 2014 - Александр Стриха: Кеширование в WordPress
WordPress Kitchen 2014 - Александр Стриха: Кеширование в WordPress
WordCamp Kyiv
 
AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS Directives
Eyal Vardi
 
Karan chanana
Karan chananaKaran chanana
Karan chanana
karan chanana
 
Discuss the scrollable result set in jdbc
Discuss the scrollable result set in jdbcDiscuss the scrollable result set in jdbc
Discuss the scrollable result set in jdbc
manojmanoj218596
 
안드로이드 세미나 2
안드로이드 세미나 2안드로이드 세미나 2
안드로이드 세미나 2
ang0123dev
 
How kris-writes-symfony-apps-london
How kris-writes-symfony-apps-londonHow kris-writes-symfony-apps-london
How kris-writes-symfony-apps-london
Kris Wallsmith
 
안드로이드 세미나 2
안드로이드 세미나 2안드로이드 세미나 2
안드로이드 세미나 2
Chul Ju Hong
 
Transaction Management Tool
Transaction Management ToolTransaction Management Tool
Transaction Management ToolPeeyush Ranjan
 
jQuery basics
jQuery basicsjQuery basics
jQuery basics
Stijn Van Minnebruggen
 
Building a Mobile App with Sencha Touch
Building a Mobile App with Sencha TouchBuilding a Mobile App with Sencha Touch
Building a Mobile App with Sencha TouchJames Pearce
 
Aspdevice - Asp Fast Crud introdution
Aspdevice - Asp Fast Crud introdutionAspdevice - Asp Fast Crud introdution
Aspdevice - Asp Fast Crud introdution
Adriano Mendes
 

What's hot (20)

MVest Spring Job Execution
MVest Spring Job ExecutionMVest Spring Job Execution
MVest Spring Job Execution
 
XQDT - XQuery Getting Momentum in Eclipse
XQDT - XQuery Getting Momentum in EclipseXQDT - XQuery Getting Momentum in Eclipse
XQDT - XQuery Getting Momentum in Eclipse
 
Couchdb
CouchdbCouchdb
Couchdb
 
AngularJS Services
AngularJS ServicesAngularJS Services
AngularJS Services
 
AngularJS Routing
AngularJS RoutingAngularJS Routing
AngularJS Routing
 
Add loop shortcode
Add loop shortcodeAdd loop shortcode
Add loop shortcode
 
Growing jQuery
Growing jQueryGrowing jQuery
Growing jQuery
 
Sins Against Drupal 2
Sins Against Drupal 2Sins Against Drupal 2
Sins Against Drupal 2
 
AngulrJS Overview
AngulrJS OverviewAngulrJS Overview
AngulrJS Overview
 
WordPress Kitchen 2014 - Александр Стриха: Кеширование в WordPress
WordPress Kitchen 2014 - Александр Стриха: Кеширование в WordPress WordPress Kitchen 2014 - Александр Стриха: Кеширование в WordPress
WordPress Kitchen 2014 - Александр Стриха: Кеширование в WordPress
 
AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS Directives
 
Karan chanana
Karan chananaKaran chanana
Karan chanana
 
Discuss the scrollable result set in jdbc
Discuss the scrollable result set in jdbcDiscuss the scrollable result set in jdbc
Discuss the scrollable result set in jdbc
 
안드로이드 세미나 2
안드로이드 세미나 2안드로이드 세미나 2
안드로이드 세미나 2
 
How kris-writes-symfony-apps-london
How kris-writes-symfony-apps-londonHow kris-writes-symfony-apps-london
How kris-writes-symfony-apps-london
 
안드로이드 세미나 2
안드로이드 세미나 2안드로이드 세미나 2
안드로이드 세미나 2
 
Transaction Management Tool
Transaction Management ToolTransaction Management Tool
Transaction Management Tool
 
jQuery basics
jQuery basicsjQuery basics
jQuery basics
 
Building a Mobile App with Sencha Touch
Building a Mobile App with Sencha TouchBuilding a Mobile App with Sencha Touch
Building a Mobile App with Sencha Touch
 
Aspdevice - Asp Fast Crud introdution
Aspdevice - Asp Fast Crud introdutionAspdevice - Asp Fast Crud introdution
Aspdevice - Asp Fast Crud introdution
 

Similar to Não alimente os trolls: JavaScript é bonito - FrontInSM 2015

Introduction to ECMAScript 2015
Introduction to ECMAScript 2015Introduction to ECMAScript 2015
Introduction to ECMAScript 2015
Tomasz Dziuda
 
ESNext for humans - LvivJS 16 August 2014
ESNext for humans - LvivJS 16 August 2014ESNext for humans - LvivJS 16 August 2014
ESNext for humans - LvivJS 16 August 2014
Jan Jongboom
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applicationselliando dias
 
Implement threads and a GUI interface using advanced Java Swing clas.pdf
Implement threads and a GUI interface using advanced Java Swing clas.pdfImplement threads and a GUI interface using advanced Java Swing clas.pdf
Implement threads and a GUI interface using advanced Java Swing clas.pdf
amrishinda
 
Building Your First Widget
Building Your First WidgetBuilding Your First Widget
Building Your First Widget
Chris Wilcoxson
 
R57php 1231677414471772-2
R57php 1231677414471772-2R57php 1231677414471772-2
R57php 1231677414471772-2
ady36
 
Scala, XML and GAE
Scala, XML and GAEScala, XML and GAE
Scala, XML and GAE
markryall
 
Simple Photo Processing and Web Display with Perl
Simple Photo Processing and Web Display with PerlSimple Photo Processing and Web Display with Perl
Simple Photo Processing and Web Display with Perl
Kent Cowgill
 
Sphinx on Rails
Sphinx on RailsSphinx on Rails
Sphinx on Rails
freelancing_god
 
Test du futur avec Spock
Test du futur avec SpockTest du futur avec Spock
Test du futur avec Spock
CARA_Lyon
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ Etsy
Nishan Subedi
 
Shkrubbel for Open Web Camp 3
Shkrubbel for Open Web Camp 3Shkrubbel for Open Web Camp 3
Shkrubbel for Open Web Camp 3kitthod
 
I Have the following Java program in which converts Date to Words an.pdf
I Have the following Java program in which converts Date to Words an.pdfI Have the following Java program in which converts Date to Words an.pdf
I Have the following Java program in which converts Date to Words an.pdf
allystraders
 
JSARToolKit / LiveChromaKey / LivePointers - Next gen of AR
JSARToolKit / LiveChromaKey / LivePointers - Next gen of ARJSARToolKit / LiveChromaKey / LivePointers - Next gen of AR
JSARToolKit / LiveChromaKey / LivePointers - Next gen of AR
Yusuke Kawasaki
 
Ad java prac sol set
Ad java prac sol setAd java prac sol set
Ad java prac sol set
Iram Ramrajkar
 
"this" in JavaScript
"this" in JavaScript"this" in JavaScript
"this" in JavaScript
Martha Schumann
 
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptWorkshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScript
Visual Engineering
 
JavaScript - Like a Box of Chocolates - jsDay
JavaScript - Like a Box of Chocolates - jsDayJavaScript - Like a Box of Chocolates - jsDay
JavaScript - Like a Box of Chocolates - jsDay
Robert Nyman
 

Similar to Não alimente os trolls: JavaScript é bonito - FrontInSM 2015 (20)

Introduction to ECMAScript 2015
Introduction to ECMAScript 2015Introduction to ECMAScript 2015
Introduction to ECMAScript 2015
 
R57.Php
R57.PhpR57.Php
R57.Php
 
ESNext for humans - LvivJS 16 August 2014
ESNext for humans - LvivJS 16 August 2014ESNext for humans - LvivJS 16 August 2014
ESNext for humans - LvivJS 16 August 2014
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
 
Implement threads and a GUI interface using advanced Java Swing clas.pdf
Implement threads and a GUI interface using advanced Java Swing clas.pdfImplement threads and a GUI interface using advanced Java Swing clas.pdf
Implement threads and a GUI interface using advanced Java Swing clas.pdf
 
Building Your First Widget
Building Your First WidgetBuilding Your First Widget
Building Your First Widget
 
R57php 1231677414471772-2
R57php 1231677414471772-2R57php 1231677414471772-2
R57php 1231677414471772-2
 
Scala, XML and GAE
Scala, XML and GAEScala, XML and GAE
Scala, XML and GAE
 
Simple Photo Processing and Web Display with Perl
Simple Photo Processing and Web Display with PerlSimple Photo Processing and Web Display with Perl
Simple Photo Processing and Web Display with Perl
 
Javascript
JavascriptJavascript
Javascript
 
Sphinx on Rails
Sphinx on RailsSphinx on Rails
Sphinx on Rails
 
Test du futur avec Spock
Test du futur avec SpockTest du futur avec Spock
Test du futur avec Spock
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ Etsy
 
Shkrubbel for Open Web Camp 3
Shkrubbel for Open Web Camp 3Shkrubbel for Open Web Camp 3
Shkrubbel for Open Web Camp 3
 
I Have the following Java program in which converts Date to Words an.pdf
I Have the following Java program in which converts Date to Words an.pdfI Have the following Java program in which converts Date to Words an.pdf
I Have the following Java program in which converts Date to Words an.pdf
 
JSARToolKit / LiveChromaKey / LivePointers - Next gen of AR
JSARToolKit / LiveChromaKey / LivePointers - Next gen of ARJSARToolKit / LiveChromaKey / LivePointers - Next gen of AR
JSARToolKit / LiveChromaKey / LivePointers - Next gen of AR
 
Ad java prac sol set
Ad java prac sol setAd java prac sol set
Ad java prac sol set
 
"this" in JavaScript
"this" in JavaScript"this" in JavaScript
"this" in JavaScript
 
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptWorkshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScript
 
JavaScript - Like a Box of Chocolates - jsDay
JavaScript - Like a Box of Chocolates - jsDayJavaScript - Like a Box of Chocolates - jsDay
JavaScript - Like a Box of Chocolates - jsDay
 

More from Rafael Specht da Silva

Processamento Digital de Sinais com Javascript - RSJS 2015
Processamento Digital de Sinais com Javascript - RSJS 2015Processamento Digital de Sinais com Javascript - RSJS 2015
Processamento Digital de Sinais com Javascript - RSJS 2015
Rafael Specht da Silva
 
Digital Signal Processing w/ Javascript
Digital Signal Processing w/ JavascriptDigital Signal Processing w/ Javascript
Digital Signal Processing w/ Javascript
Rafael Specht da Silva
 
Javascript Ilegível
Javascript IlegívelJavascript Ilegível
Javascript Ilegível
Rafael Specht da Silva
 
Javascript ao Infinito e Além TDC Porto Alegre 2014
Javascript ao Infinito e Além TDC Porto Alegre 2014Javascript ao Infinito e Além TDC Porto Alegre 2014
Javascript ao Infinito e Além TDC Porto Alegre 2014
Rafael Specht da Silva
 
Web audio api TDC
Web audio api TDCWeb audio api TDC
Web audio api TDC
Rafael Specht da Silva
 
Javascript ao Infinito e Além
Javascript ao Infinito e AlémJavascript ao Infinito e Além
Javascript ao Infinito e Além
Rafael Specht da Silva
 
A esquecida camada física ou porquê minha internet é tão lenta
A esquecida camada física ou porquê minha internet é tão lentaA esquecida camada física ou porquê minha internet é tão lenta
A esquecida camada física ou porquê minha internet é tão lenta
Rafael Specht da Silva
 

More from Rafael Specht da Silva (7)

Processamento Digital de Sinais com Javascript - RSJS 2015
Processamento Digital de Sinais com Javascript - RSJS 2015Processamento Digital de Sinais com Javascript - RSJS 2015
Processamento Digital de Sinais com Javascript - RSJS 2015
 
Digital Signal Processing w/ Javascript
Digital Signal Processing w/ JavascriptDigital Signal Processing w/ Javascript
Digital Signal Processing w/ Javascript
 
Javascript Ilegível
Javascript IlegívelJavascript Ilegível
Javascript Ilegível
 
Javascript ao Infinito e Além TDC Porto Alegre 2014
Javascript ao Infinito e Além TDC Porto Alegre 2014Javascript ao Infinito e Além TDC Porto Alegre 2014
Javascript ao Infinito e Além TDC Porto Alegre 2014
 
Web audio api TDC
Web audio api TDCWeb audio api TDC
Web audio api TDC
 
Javascript ao Infinito e Além
Javascript ao Infinito e AlémJavascript ao Infinito e Além
Javascript ao Infinito e Além
 
A esquecida camada física ou porquê minha internet é tão lenta
A esquecida camada física ou porquê minha internet é tão lentaA esquecida camada física ou porquê minha internet é tão lenta
A esquecida camada física ou porquê minha internet é tão lenta
 

Não alimente os trolls: JavaScript é bonito - FrontInSM 2015

  • 1. Não alimente os trolls: Javascript é bonito! @rafael_sps
  • 2. Quem? Tecnólogo em Telecomunicações IFSul Rafael Specht da Silva
  • 3.
  • 4.
  • 5.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16. “Se JavaScript não fosse tão feia, um livro chamado ‘JavaScript: The Good Parts’ não seria o best-seller da linguagem na Amazon” http://simpleprogrammer.com/2013/05/06/why-javascript-is-doomed/
  • 18. typeof {} // ‘object’ typeof [] // ‘object’
  • 19. typeof null // ‘object’ typeof undefined // ‘undefined’ undefined == null // true
  • 20. +
  • 21. var n1 = 2; var n2 = 3; n1 + n2 // 5 var n1 = 2 var n2 = ‘3’ n1 + n2 // ‘23’
  • 22.
  • 25. 0 == false // true 0 === false // false 1 == true // true 1 === true // false
  • 26. var url1 = 'http://localhost/rs/santa-maria' var url2 = 'http://localhost/' var getState = function (url) { var stateMatch = url.match(//[a-z]{2}//gi); var state = null; if (stateMatch !== null && stateMatch.length > 0) { state = stateMatch[0].replace(///g, ''); } return state; } getState(url1); // ‘rs’ getState(url2); // null
  • 27. “Se você trata null e undefined igualmente, é recompensado com comparações mais simples” https://speakerdeck.com/getify/new-rules-for-javascript
  • 28. if (stateMatch !== null && stateMatch.length > 0) { state = stateMatch[0].replace(///g, ''); } if (stateMatch && stateMatch.length) { state = stateMatch[0].replace(///g, ''); }
  • 29. var data = {name: 'Luke', surname: 'Skywalker'} var User = function (name, surname) { this.name = name; this.surname = surname; this.getCompleteName = function () { return this.name + ' ' + this.surname; } } var user = new User(data.name, data.surname) user.getCompleteName(); // 'Luke Skywalker'
  • 30. var data = {name: 'Luke'} var user = new User(data.name, data.surname) user.getCompleteName(); // 'Luke undefined'
  • 31. var data = {name: 'Luke'} var User = function (name, surname) { this.name = name; this.surname = surname || ''; this.getCompleteName = function () { return this.name + ' ' + this.surname; } } var user = new User(data.name, data.surname) user.getCompleteName(); // 'Luke '
  • 32. this
  • 33. var UserView = function () { function setName (name) { this.name = name; } function setEvents () { var that = this; $('.hit').on('click', function () { console.log(this); // <button class="hit">Hit me!</button> $(this).toggleClass('odd'); that.setName($('.name').val()); }); } return { setEvents: setEvents, setName: setName } }
  • 34. function setEvents () { var that = this; $('.hit').on('click', function () { console.log(this); $(this).toggleClass('odd'); that.setName($('.name').val()); }); }
  • 35. function setEvents () { var button = $('.hit'); function handler () { console.log(this); button.toggleClass('odd'); this.setName($('.name').val()); } button.on('click', handler.bind(this)); } https://github.com/rssilva/presentations/blob/master/front-in-sm-2015/thisWorld/ex1.html
  • 36.
  • 37. var Human = { setName: function (name) { console.log(this); this.name = name; }, sayHi: function () { return 'Hi! My name is ' + this.name + '!'; } }
  • 38. var Ninja = { setName: Human.setName, setStealhLevel: function (level) { console.log(this) this.stealthLevel = level; } }
  • 39. var Turtle = { setHullLevel: function (level) { console.log(this); this.hullLevel = level; } } var NinjaTurtle = { setName: Ninja.setName, setStealhLevel: Ninja.setStealhLevel, setHullLevel: Turtle.setHullLevel }
  • 40. var raphael = Object.create(NinjaTurtle, {}); raphael.setName('Raphael'); raphael.setStealhLevel(50); raphael.setHullLevel(100); console.log(raphael); console.log(raphael.sayHi); https://github.com/rssilva/presentations/blob/master/front-in-sm-2015/thisWorld/ex2.html
  • 42. var a = [1, 2, 3]; var b = a; b.pop(); console.log(a); // [1, 2] console.log(b); // [1, 2]
  • 44. É importante: - ter bom-humor! - criticar construtivamente - aprender os paradigmas
  • 45. Toda linguagem tem peculiaridades. Aprender a lidar com elas é parte do nosso trabalho.