SlideShare ist ein Scribd-Unternehmen logo
1 von 36
Classing up ES6
Andy Sharman // @udjamaflip
Let’s travel back...
Remember when we wrote
JS like this...
<a href="mypage.html" onclick="alert('no, you cannot go to my page'); return;">
Go to my page
</a>
...and when we used it for
things like this?
Moving forward we started
getting structured
function UserManager(){
this.userDetails = {};
}
UserManager.prototype.setName = function( firstName, lastName ) {
return this.userDetails.name = firstName + ' ' + lastName;
};
var billy = new UserManager();
billy.setName('Billy', 'Smith');
console.log(billy);
We started using JS to fix
browsers...
...then those browsers died,
so what now?
Then we built on top of JS
The industry have been
making classes in JS
Mootools
var MyClass = new Class(properties);
Ember
App.Person = Ember.Object.extend({
jQuery
jQuery.extend(target [,object1] [,objectN])
React
React.createClass({
Angular
var HelloWorld = angular.module("Demo", []);
HelloWorld.factory("FooBar", function() {});
The Code
Classes
class car {
}
class engine {
}
Inheritance
class car extends engine {
}
class engine {
}
Inheritance
class car extends engine {
}
var myCar = new car();
car.start();
car.stop();
class engine {
start() {
this.engineStatus = 'on';
}
stop() {
this.engineStatus = 'off';
}
}
Inheritance
class car extends engine {
}
var myCar = new car();
car.start();
car.stop();
class engine {
start() {
this.engineStatus = 'on';
}
stop() {
this.engineStatus = 'off';
}
}
Constructors
class car extends engine {
constructor() {
this.start();
}
}
var myCar = new car();
car.stop();
class engine {
start() {
this.engineStatus = 'on';
}
stop() {
this.engineStatus = 'off';
}
}
Constructors + Inheritance
class car extends engine {
constructor() {
super();
}
}
var myCar = new car();
class engine {
constructor() {
console.log('engine initiated');
}
}
//output: engine initiated
Constructors + Inheritance
class car extends engine {
constructor() {
super();
}
}
var myCar = new car();
class engine {
constructor() {
console.log('engine initiated');
}
}
//output: engine initiated
Getters/Setters
class car extends engine {
constructor(engineSize, engineFuel) {
this.stats = [
engineSize,
engineFuel
];
}
}
var myCar = new car(
'v6',
'Kerosene'
);
class engine {
get stats() {
return {
'size': this.size || 'v8',
'fuel': this.fuel || 'Petrol'
}
}
set stats(data) {
this.size = data[0] || 'v8';
this.fuel = data[1] || 'Petrol';
}
}
Getters/Setters
class car extends engine {
constructor(engineSize, engineFuel) {
this.stats = [
engineSize,
engineFuel
];
}
}
var myCar = new car(
'v6',
'Kerosene'
);
class engine {
get stats() {
return {
'size': this.size || 'v8',
'fuel': this.fuel || 'Petrol'
}
}
set stats(data) {
this.size = data[0] || 'v8';
this.fuel = data[1] || 'Petrol';
}
}
Default parameters
class car extends engine {
constructor(engineSize = 'v8', engineFuel = 'Petrol') {
this.stats = [
engineSize,
engineFuel
];
}
}
var myCar = new car();
class engine {
get stats() {
return {
'size': this.size || 'v8',
'fuel': this.fuel || 'Petrol'
}
}
set stats(data) {
this.size = data[0];
this.fuel = data[1];
}
}
Default parameters
class car extends engine {
constructor(engineSize = 'v8', engineFuel = 'Petrol') {
this.stats = [
engineSize,
engineFuel
];
}
}
var myCar = new car();
class engine {
get stats() {
return {
'size': this.size || 'v8',
'fuel': this.fuel || 'Petrol'
}
}
set stats(data) {
this.size = data[0];
this.fuel = data[1];
}
}
Rest Parameters
class car extends engine {
constructor(...engineData) {
this.stats = engineData;
}
}
var myCar = new car(
'v6',
'Kerosene'
);
class engine {
get stats() {
return {
'size': this.size || 'v8',
'fuel': this.fuel || 'Petrol'
}
}
set stats(data) {
this.size = data[0] || 'v8';
this.fuel = data[1] || 'Petrol';
}
}
Rest Parameters
class car extends engine {
constructor(...engineData) {
this.stats = engineData;
}
}
var myCar = new car(
'v6',
'Kerosene'
);
class engine {
get stats() {
return {
'size': this.size || 'v8',
'fuel': this.fuel || 'Petrol'
}
}
set stats(data) {
this.size = data[0] || 'v8';
this.fuel = data[1] || 'Petrol';
}
}
Arrow functions
class App {
constructor() {
var request = new XMLHttpRequest();
request.open('GET', 'my-api/endpoint', true);
request.onreadystatechange = () => {
if (request.readyState != 4 || request.status != 200) return;
this.data = request.responseText;
this.startApp();
};
request.send();
}
this.startApp() { }
}
Arrow functions
class App {
constructor() {
var request = new XMLHttpRequest();
request.open('GET', 'my-api/endpoint', true);
request.onreadystatechange = () => {
if (request.readyState != 4 || request.status != 200) return;
this.data = request.responseText;
this.startApp();
};
request.send();
}
this.startApp() { }
}
Arrow functions
class App {
constructor() {
var request = new XMLHttpRequest();
request.open('GET', 'my-api/endpoint', true);
request.onreadystatechange = () => {
if (request.readyState != 4 || request.status != 200) return;
this.data = request.responseText;
this.startApp();
};
request.send();
}
this.startApp() { }
}
Isn’t it just syntactic sugar?
ubai by Liji Jinaraj
Leaning tower of Pisa by Gimli_36
Pyramids of Giza by Kallerna
Support
Compatibility
Firefox & MS Edge have
impressive support
Screw your compatibility
I’ll make my own compatibility
With blackjack, and transpilers
Thanks
Andy Sharman // @udjamaflip

Weitere ähnliche Inhalte

Was ist angesagt?

Mulberry: A Mobile App Development Toolkit
Mulberry: A Mobile App Development ToolkitMulberry: A Mobile App Development Toolkit
Mulberry: A Mobile App Development ToolkitRebecca Murphey
 
A New Baseline for Front-End Devs
A New Baseline for Front-End DevsA New Baseline for Front-End Devs
A New Baseline for Front-End DevsRebecca Murphey
 
Building Large jQuery Applications
Building Large jQuery ApplicationsBuilding Large jQuery Applications
Building Large jQuery ApplicationsRebecca Murphey
 
Sprout core and performance
Sprout core and performanceSprout core and performance
Sprout core and performanceYehuda Katz
 
JavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScriptJavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScriptLaurence Svekis ✔
 
Smooth scrolling in UITableView and UICollectionView
Smooth scrolling in UITableView and UICollectionViewSmooth scrolling in UITableView and UICollectionView
Smooth scrolling in UITableView and UICollectionViewAndrea Prearo
 
Using Objects to Organize your jQuery Code
Using Objects to Organize your jQuery CodeUsing Objects to Organize your jQuery Code
Using Objects to Organize your jQuery CodeRebecca Murphey
 
Immutable Libraries for React
Immutable Libraries for ReactImmutable Libraries for React
Immutable Libraries for Reactstbaechler
 
Angular js performance improvements
Angular js performance improvementsAngular js performance improvements
Angular js performance improvementsSigmoid
 
jQuery and Rails, Sitting in a Tree
jQuery and Rails, Sitting in a TreejQuery and Rails, Sitting in a Tree
jQuery and Rails, Sitting in a Treeadamlogic
 
Beyond the DOM: Sane Structure for JS Apps
Beyond the DOM: Sane Structure for JS AppsBeyond the DOM: Sane Structure for JS Apps
Beyond the DOM: Sane Structure for JS AppsRebecca Murphey
 
WordPress plugin #3
WordPress plugin #3WordPress plugin #3
WordPress plugin #3giwoolee
 
Chris Holland "Leveraging Typed Exceptions for Cleaner Error Handling"
Chris Holland "Leveraging Typed Exceptions for Cleaner Error Handling"Chris Holland "Leveraging Typed Exceptions for Cleaner Error Handling"
Chris Holland "Leveraging Typed Exceptions for Cleaner Error Handling"Fwdays
 

Was ist angesagt? (19)

Dojo Confessions
Dojo ConfessionsDojo Confessions
Dojo Confessions
 
UI@Docker
UI@DockerUI@Docker
UI@Docker
 
Mulberry: A Mobile App Development Toolkit
Mulberry: A Mobile App Development ToolkitMulberry: A Mobile App Development Toolkit
Mulberry: A Mobile App Development Toolkit
 
A New Baseline for Front-End Devs
A New Baseline for Front-End DevsA New Baseline for Front-End Devs
A New Baseline for Front-End Devs
 
Building Large jQuery Applications
Building Large jQuery ApplicationsBuilding Large jQuery Applications
Building Large jQuery Applications
 
Sprout core and performance
Sprout core and performanceSprout core and performance
Sprout core and performance
 
The Customizer
The CustomizerThe Customizer
The Customizer
 
JavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScriptJavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScript
 
Smooth scrolling in UITableView and UICollectionView
Smooth scrolling in UITableView and UICollectionViewSmooth scrolling in UITableView and UICollectionView
Smooth scrolling in UITableView and UICollectionView
 
jQuery secrets
jQuery secretsjQuery secrets
jQuery secrets
 
Using Objects to Organize your jQuery Code
Using Objects to Organize your jQuery CodeUsing Objects to Organize your jQuery Code
Using Objects to Organize your jQuery Code
 
Immutable Libraries for React
Immutable Libraries for ReactImmutable Libraries for React
Immutable Libraries for React
 
Angular js performance improvements
Angular js performance improvementsAngular js performance improvements
Angular js performance improvements
 
The Settings API
The Settings APIThe Settings API
The Settings API
 
jQuery and Rails, Sitting in a Tree
jQuery and Rails, Sitting in a TreejQuery and Rails, Sitting in a Tree
jQuery and Rails, Sitting in a Tree
 
Beyond the DOM: Sane Structure for JS Apps
Beyond the DOM: Sane Structure for JS AppsBeyond the DOM: Sane Structure for JS Apps
Beyond the DOM: Sane Structure for JS Apps
 
WordPress plugin #3
WordPress plugin #3WordPress plugin #3
WordPress plugin #3
 
Chris Holland "Leveraging Typed Exceptions for Cleaner Error Handling"
Chris Holland "Leveraging Typed Exceptions for Cleaner Error Handling"Chris Holland "Leveraging Typed Exceptions for Cleaner Error Handling"
Chris Holland "Leveraging Typed Exceptions for Cleaner Error Handling"
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 

Andere mochten auch

Andere mochten auch (14)

Mac (9)
Mac (9)Mac (9)
Mac (9)
 
Mac (7)
Mac (7)Mac (7)
Mac (7)
 
Mac (12)
Mac (12)Mac (12)
Mac (12)
 
Mac (11)
Mac (11)Mac (11)
Mac (11)
 
Presentacion de filosofia
Presentacion de filosofiaPresentacion de filosofia
Presentacion de filosofia
 
Mac (6)
Mac (6)Mac (6)
Mac (6)
 
Mac (13)
Mac (13)Mac (13)
Mac (13)
 
Mac (5)
Mac (5)Mac (5)
Mac (5)
 
Mac (4)
Mac (4)Mac (4)
Mac (4)
 
Mac (8)
Mac (8)Mac (8)
Mac (8)
 
Norma tecnica sectorial ts gt
Norma tecnica sectorial ts gtNorma tecnica sectorial ts gt
Norma tecnica sectorial ts gt
 
Granulometría, Minas y Canteras
Granulometría, Minas y CanterasGranulometría, Minas y Canteras
Granulometría, Minas y Canteras
 
Cuál es el papel de la química
Cuál es el papel de la químicaCuál es el papel de la química
Cuál es el papel de la química
 
Peta kognitif pendekatan pada bk
Peta kognitif pendekatan pada bkPeta kognitif pendekatan pada bk
Peta kognitif pendekatan pada bk
 

Ähnlich wie Classing up ES6 - Web Directions code 2015 (1)

Gutenberg sous le capot, modules réutilisables
Gutenberg sous le capot, modules réutilisablesGutenberg sous le capot, modules réutilisables
Gutenberg sous le capot, modules réutilisablesRiad Benguella
 
Getting classy with ES6
Getting classy with ES6Getting classy with ES6
Getting classy with ES6Andy Sharman
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说Ting Lv
 
Taming forms with React
Taming forms with ReactTaming forms with React
Taming forms with ReactGreeceJS
 
Solid principles
Solid principlesSolid principles
Solid principlesSahil Kumar
 
Protractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applicationsProtractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applicationsLudmila Nesvitiy
 
Image manipulation in WordPress 3.5
Image manipulation in WordPress 3.5Image manipulation in WordPress 3.5
Image manipulation in WordPress 3.5Marko Heijnen
 
C#i need help creating the instance of stream reader to read from .pdf
C#i need help creating the instance of stream reader to read from .pdfC#i need help creating the instance of stream reader to read from .pdf
C#i need help creating the instance of stream reader to read from .pdfajantha11
 
C-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression CalculatorC-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression CalculatorNeeraj Kaushik
 
Creating a Facebook Clone - Part X - Transcript.pdf
Creating a Facebook Clone - Part X - Transcript.pdfCreating a Facebook Clone - Part X - Transcript.pdf
Creating a Facebook Clone - Part X - Transcript.pdfShaiAlmog1
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ EtsyNishan Subedi
 
Getting started with ES6
Getting started with ES6Getting started with ES6
Getting started with ES6Nitay Neeman
 
JSLab. Алексей Волков. "React на практике"
JSLab. Алексей Волков. "React на практике"JSLab. Алексей Волков. "React на практике"
JSLab. Алексей Волков. "React на практике"GeeksLab Odessa
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For BeginnersJonathan Wage
 
Reliable Javascript
Reliable Javascript Reliable Javascript
Reliable Javascript Glenn Stovall
 
Introduction to backbone presentation
Introduction to backbone presentationIntroduction to backbone presentation
Introduction to backbone presentationBrian Hogg
 

Ähnlich wie Classing up ES6 - Web Directions code 2015 (1) (20)

Gutenberg sous le capot, modules réutilisables
Gutenberg sous le capot, modules réutilisablesGutenberg sous le capot, modules réutilisables
Gutenberg sous le capot, modules réutilisables
 
Getting classy with ES6
Getting classy with ES6Getting classy with ES6
Getting classy with ES6
 
Clean Javascript
Clean JavascriptClean Javascript
Clean Javascript
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说
 
Taming forms with React
Taming forms with ReactTaming forms with React
Taming forms with React
 
Solid principles
Solid principlesSolid principles
Solid principles
 
Protractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applicationsProtractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applications
 
Image manipulation in WordPress 3.5
Image manipulation in WordPress 3.5Image manipulation in WordPress 3.5
Image manipulation in WordPress 3.5
 
C#i need help creating the instance of stream reader to read from .pdf
C#i need help creating the instance of stream reader to read from .pdfC#i need help creating the instance of stream reader to read from .pdf
C#i need help creating the instance of stream reader to read from .pdf
 
C-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression CalculatorC-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression Calculator
 
Creating a Facebook Clone - Part X - Transcript.pdf
Creating a Facebook Clone - Part X - Transcript.pdfCreating a Facebook Clone - Part X - Transcript.pdf
Creating a Facebook Clone - Part X - Transcript.pdf
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ Etsy
 
Getting started with ES6
Getting started with ES6Getting started with ES6
Getting started with ES6
 
JSLab. Алексей Волков. "React на практике"
JSLab. Алексей Волков. "React на практике"JSLab. Алексей Волков. "React на практике"
JSLab. Алексей Волков. "React на практике"
 
C++ L10-Inheritance
C++ L10-InheritanceC++ L10-Inheritance
C++ L10-Inheritance
 
Unittests für Dummies
Unittests für DummiesUnittests für Dummies
Unittests für Dummies
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
Reliable Javascript
Reliable Javascript Reliable Javascript
Reliable Javascript
 
Eclipse Tricks
Eclipse TricksEclipse Tricks
Eclipse Tricks
 
Introduction to backbone presentation
Introduction to backbone presentationIntroduction to backbone presentation
Introduction to backbone presentation
 

Classing up ES6 - Web Directions code 2015 (1)

  • 1. Classing up ES6 Andy Sharman // @udjamaflip
  • 3. Remember when we wrote JS like this... <a href="mypage.html" onclick="alert('no, you cannot go to my page'); return;"> Go to my page </a>
  • 4. ...and when we used it for things like this?
  • 5. Moving forward we started getting structured function UserManager(){ this.userDetails = {}; } UserManager.prototype.setName = function( firstName, lastName ) { return this.userDetails.name = firstName + ' ' + lastName; }; var billy = new UserManager(); billy.setName('Billy', 'Smith'); console.log(billy);
  • 6. We started using JS to fix browsers...
  • 7. ...then those browsers died, so what now?
  • 8. Then we built on top of JS
  • 9. The industry have been making classes in JS Mootools var MyClass = new Class(properties); Ember App.Person = Ember.Object.extend({ jQuery jQuery.extend(target [,object1] [,objectN]) React React.createClass({ Angular var HelloWorld = angular.module("Demo", []); HelloWorld.factory("FooBar", function() {});
  • 10.
  • 13. Inheritance class car extends engine { } class engine { }
  • 14. Inheritance class car extends engine { } var myCar = new car(); car.start(); car.stop(); class engine { start() { this.engineStatus = 'on'; } stop() { this.engineStatus = 'off'; } }
  • 15. Inheritance class car extends engine { } var myCar = new car(); car.start(); car.stop(); class engine { start() { this.engineStatus = 'on'; } stop() { this.engineStatus = 'off'; } }
  • 16. Constructors class car extends engine { constructor() { this.start(); } } var myCar = new car(); car.stop(); class engine { start() { this.engineStatus = 'on'; } stop() { this.engineStatus = 'off'; } }
  • 17. Constructors + Inheritance class car extends engine { constructor() { super(); } } var myCar = new car(); class engine { constructor() { console.log('engine initiated'); } } //output: engine initiated
  • 18. Constructors + Inheritance class car extends engine { constructor() { super(); } } var myCar = new car(); class engine { constructor() { console.log('engine initiated'); } } //output: engine initiated
  • 19. Getters/Setters class car extends engine { constructor(engineSize, engineFuel) { this.stats = [ engineSize, engineFuel ]; } } var myCar = new car( 'v6', 'Kerosene' ); class engine { get stats() { return { 'size': this.size || 'v8', 'fuel': this.fuel || 'Petrol' } } set stats(data) { this.size = data[0] || 'v8'; this.fuel = data[1] || 'Petrol'; } }
  • 20. Getters/Setters class car extends engine { constructor(engineSize, engineFuel) { this.stats = [ engineSize, engineFuel ]; } } var myCar = new car( 'v6', 'Kerosene' ); class engine { get stats() { return { 'size': this.size || 'v8', 'fuel': this.fuel || 'Petrol' } } set stats(data) { this.size = data[0] || 'v8'; this.fuel = data[1] || 'Petrol'; } }
  • 21. Default parameters class car extends engine { constructor(engineSize = 'v8', engineFuel = 'Petrol') { this.stats = [ engineSize, engineFuel ]; } } var myCar = new car(); class engine { get stats() { return { 'size': this.size || 'v8', 'fuel': this.fuel || 'Petrol' } } set stats(data) { this.size = data[0]; this.fuel = data[1]; } }
  • 22. Default parameters class car extends engine { constructor(engineSize = 'v8', engineFuel = 'Petrol') { this.stats = [ engineSize, engineFuel ]; } } var myCar = new car(); class engine { get stats() { return { 'size': this.size || 'v8', 'fuel': this.fuel || 'Petrol' } } set stats(data) { this.size = data[0]; this.fuel = data[1]; } }
  • 23. Rest Parameters class car extends engine { constructor(...engineData) { this.stats = engineData; } } var myCar = new car( 'v6', 'Kerosene' ); class engine { get stats() { return { 'size': this.size || 'v8', 'fuel': this.fuel || 'Petrol' } } set stats(data) { this.size = data[0] || 'v8'; this.fuel = data[1] || 'Petrol'; } }
  • 24. Rest Parameters class car extends engine { constructor(...engineData) { this.stats = engineData; } } var myCar = new car( 'v6', 'Kerosene' ); class engine { get stats() { return { 'size': this.size || 'v8', 'fuel': this.fuel || 'Petrol' } } set stats(data) { this.size = data[0] || 'v8'; this.fuel = data[1] || 'Petrol'; } }
  • 25. Arrow functions class App { constructor() { var request = new XMLHttpRequest(); request.open('GET', 'my-api/endpoint', true); request.onreadystatechange = () => { if (request.readyState != 4 || request.status != 200) return; this.data = request.responseText; this.startApp(); }; request.send(); } this.startApp() { } }
  • 26. Arrow functions class App { constructor() { var request = new XMLHttpRequest(); request.open('GET', 'my-api/endpoint', true); request.onreadystatechange = () => { if (request.readyState != 4 || request.status != 200) return; this.data = request.responseText; this.startApp(); }; request.send(); } this.startApp() { } }
  • 27. Arrow functions class App { constructor() { var request = new XMLHttpRequest(); request.open('GET', 'my-api/endpoint', true); request.onreadystatechange = () => { if (request.readyState != 4 || request.status != 200) return; this.data = request.responseText; this.startApp(); }; request.send(); } this.startApp() { } }
  • 28. Isn’t it just syntactic sugar?
  • 29. ubai by Liji Jinaraj
  • 30. Leaning tower of Pisa by Gimli_36
  • 31. Pyramids of Giza by Kallerna
  • 34. Firefox & MS Edge have impressive support
  • 35. Screw your compatibility I’ll make my own compatibility With blackjack, and transpilers
  • 36. Thanks Andy Sharman // @udjamaflip