JavaScript Classified

Post on 01-Nov-2014

323 views 1 download

Tags:

description

W wyniku różnorodnych metod implementacji przez poszczególne frameworki, w temacie klas w JavaScript zdiagnozowano rozszczepienie osobowości. Na szczęście odpowiednie lekarstwo powoli jest szykowane, o czym będę starał się opowiedzieć w tej prezentacji. Jednocześnie postaram się przypomnieć historie choroby, jej objawy i wytłumaczyć, dlaczego kuracja jest tak bardzo pożądana.

Transcript of JavaScript Classified

JavaScript

Artur Skowroński

Abstrakcja (łac. abstractio - oderwanie)

Klasyczne podejście

Konstruktor Funkcyjny

function Person(name){

this.name=name;

}

Person.prototype.show=function(){

console.log("Jestem " + this.firm);

};

Employee.prototype = new Person(); Employee.prototype.constructor = Employee;

Employee.prototype.show = function(){

Person.prototype.show.call(this);

console.log("Pracuje w firme " + this.firm);

};

Object.create For Loop

Core API

EcmaScript 3Grudzień 1999

Wyrażenia regularne

Try Catch

ECMAScript 4

Packages

NamespacesKlasy

Grudzień 2009

ECMAScript 3.1ECMAScript 5

maximally_minimal_classes

Aktualny Draft

Tworzenie i konstruktory

ECMAScript 3

function Person(name){ this.name=name; }

ECMAScript 6

class Person { constructor(name){ this.name=name; } }

Metody

Person.prototype.hello = function(){ console.log("Osoba " + this.name ); };

ECMAScript 3

class Person { (…) hello(){ console.log("Osoba "+this.name); } }

ECMAScript 6

Dziedziczenie

ECMAScript 3

Man.prototype = new Mammal(); Man.prototype.constructor = Man; !

function Man(firm){ this.firm=firm; }

ECMAScript 6

class Man extends Mammal { constructor(firm){ this.firm= firm; } }

SuperMetody

ECMAScript 3

Employee.prototype.show = function(){ Person.prototype.show.call(this); alert("Pracuje w firme " + this.firm); }

class Employee extends Person { (…) !

show(){ super() alert("Pracuje w firme " + this.firm); } !

}

ECMAScript 6

Czego jeszcze nie dostaniemy

• Zamkniętego stanu• Properties

NazwaKlasy.prototype.nazwaPop = 0;

Future editions of ECMAScript may and probably will extend the proposed class definitions. However, the intent for “ES6” is to only include the features described in this proposal. Attempting to extend this proposal is likely to result in

dead-lock that would result in the inclusion of no class definition support in “ES6”.

Podsumowując

•Standard dziedziczenia dla wszystkich !

•Naturalne Core API dla twórców Frameworków

Nadzieje

Interoperacyjność

IDE Support

Performance języka

http://sealedabstract.com/rants/why-mobile-web-apps-are-slow/

Kiedy?

http://kangax.github.io/compat-table/es6

https://github.com/google/traceur-compiler

Dziękuje bardzo… i zapraszam do pytańArtur Skowroński