Top Banner
Vanilla JS “Pode ser que você não precise de jQuery”
14

Vanilla js

Jan 12, 2017

Download

Software

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Vanilla js

Vanilla JS“Pode ser que você não precise de jQuery”

Page 2: Vanilla js

Jackson VeronezeSoftware Developer

[email protected]://jacksonveroneze.comhttps://br.linkedin.com/in/jacksonveroneze

Autores

Mario MendonçaSoftware Developer

[email protected]://br.linkedin.com/in/mario-mendonca

Page 3: Vanilla js

O que é Vanilla JSÉ JavaScript puro.

A forma apresentada, para parecer como um framework, talvez seja proposital como forma de piada já que há uma crítica sobre a proliferação de frameworks que em geral pouco agrega de fato.

Page 4: Vanilla js

VantagensO benefício mais objetivo de usar JavaScript puro ou Vanilla JS é o melhor desempenho. Outro benefício é uma melhor compreensão da linguagem que você ganha ao escrever códigos em Vanilla JS.

Page 5: Vanilla js

DesvantagensA desvantagem de usar Vanilla JS é que é mais fácil cometer erros ou perder alguma coisa, é menos amigável (que jQuery), e pode exigir desenvolver mais código para atingir objetivos que levaria menos tempo com jQuery.

Page 6: Vanilla js

Como escolherJQuery é uma boa escolha nas seguintes situações:

Para pequenos projetos, onde a performance não é um problema

Projetos simples, com prazo apertado

Grandes projetos que usam uma biblioteca ou estrutura que tem jQuery como dependência

Onde não usar jQuery incluem:

Adquirir conhecimento intermediário e avançado em JavaScript

Aplicações Web complexas

Desenvolver sua própria biblioteca

Aplicações do lado do servidor com Node.js

Page 7: Vanilla js

Events// jQuery$(document).ready(function() { // code})

// jQuery$('a').click(function() { // code…})

// Vanilladocument.addEventListener('DOMContentLoaded', function() { // code})

// Vanilla[].forEach.call(document.querySelectorAll('a'), function(el) { el.addEventListener('click', function() { // code… })})

Page 8: Vanilla js

Attributes// jQuery$('img').filter(':first').attr('alt', 'My image')

// Vanilladocument.querySelector('img').setAttribute('alt', 'My image')

Page 9: Vanilla js

Classes// jQuerynewDiv.addClass('foo')

// jQuerynewDiv.toggleClass('foo')

// VanillanewDiv.classList.add('foo')

// VanillanewDiv.classList.toggle('foo')

Page 10: Vanilla js

Selectors// jQueryvar divs = $('div')

// jQueryvar newDiv = $('<div/>')

// Vanillavar divs = document.querySelectorAll('div')

// Vanillavar newDiv = document.createElement('div')

Page 11: Vanilla js

Ajax// jQuery$.get('//example.com', function (data) { // code})

// Vanillavar httpRequest = new XMLHttpRequest()httpRequest.onreadystatechange = function (data) { // code}httpRequest.open('GET', url)httpRequest.send()

Page 12: Vanilla js

Comparação de Velocidade

Page 13: Vanilla js

Comparação de Velocidade

Page 14: Vanilla js

Referênciashttp://pt.stackoverflow.com/questions/46983/o-que-%C3%A9-o-vanilla-js

https://gist.github.com/liamcurry/2597326

http://vanilla-js.com/

http://youmightnotneedjquery.com/