Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
How to Re-Architect a JavaScript Class System
Search
Olga
May 13, 2019
Programming
0
120
How to Re-Architect a JavaScript Class System
Olga
May 13, 2019
Tweet
Share
More Decks by Olga
See All by Olga
Visual Feature Engineering for Machine Learning with React
olgapetrova
0
230
Introduction to ExtReact, ExtAngular and ExtWebComponents
olgapetrova
0
65
Visual Feature Engineering for ML with React and TensorFlow.js
olgapetrova
0
68
Web Push Notifications
olgapetrova
1
290
How to add D3.js visualization to your Ext JS application
olgapetrova
1
560
Turbo-charged Data Analysis and Visualization using Ext JS 6.2
olgapetrova
3
94
ExtJS 6: one framework for all devices
olgapetrova
1
780
Other Decks in Programming
See All in Programming
RubyKaigi Hack Space in Tokyo & 函館最速 "予習" 会 / RubyKaigi Hack Space in Tokyo & The Fastest Briefing of RubyKaigi 2026 in Hakodate
moznion
1
100
抽象データ型について学んだ
ryounasso
0
190
ぽちぽち選択するだけでOSSを読めるVSCode拡張機能
ymbigo
14
6.7k
Ruby で作る RISC-V CPU エミュレーター / RISC-V CPU emulator made with Ruby
hayaokimura
5
1.3k
データベースの技術選定を突き詰める ~複数事例から考える最適なデータベースの選び方~
nnaka2992
3
3.8k
コンポーネントライブラリで実現する、アクセシビリティの正しい実装パターン
schktjm
1
560
Cache Strategies with Redisson & Exposed
debop
0
120
『Python → TypeScript』オンボーディング奮闘記
takumi_tatsuno
1
110
衛星の軌道をWeb地図上に表示する
sankichi92
0
210
REST API設計の実践 – ベストプラクティスとその落とし穴
kentaroutakeda
2
220
私のRubyKaigi 2025 Kaigi Effect / My RubyKaigi 2025 Kaigi Effect
chobishiba
1
200
Duke on CRaC with Jakarta EE
ivargrimstad
1
560
Featured
See All Featured
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.8k
Raft: Consensus for Rubyists
vanstee
137
6.9k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
5
640
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3.2k
Speed Design
sergeychernyshev
30
960
How to Ace a Technical Interview
jacobian
276
23k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.6k
Bash Introduction
62gerente
613
210k
The Art of Programming - Codeland 2020
erikaheidi
54
13k
Into the Great Unknown - MozCon
thekraken
38
1.8k
Transcript
None
How to Re-Architect a JavaScript Class System Olga Petrova, @tyoushe
Developer Advocate, Sencha
Olga Petrova, @tyoushe Evolution of Standards and Technologies
Olga Petrova, @tyoushe
Olga Petrova, @tyoushe
Olga Petrova, @tyoushe What Makes Technology Future-Proof?
Olga Petrova, @tyoushe
Olga Petrova, @tyoushe
Olga Petrova, @tyoushe
Olga Petrova, @tyoushe Inheritance via Prototyping function MyComponent() {} MyComponent.prototype.init
= function() { //... } function MyChildComponent() {} MyChildComponent.prototype = Object.create(new MyComponent()); MyChildComponent.prototype.destroy = function() { //... } var cmp = new MyChildComponent(); cmp.init(); cmp.destroy();
Olga Petrova, @tyoushe
Olga Petrova, @tyoushe
Olga Petrova, @tyoushe
Olga Petrova, @tyoushe
Olga Petrova, @tyoushe Ext JS Class System ✔ Inheritance ✔
Config properties ✔ Dependencies ✔ Mixins ✔ Overrides ✔ Build tool
Olga Petrova, @tyoushe Ext JS Class Ext.define('My.own.Component', { extend: 'Ext.Component',
requires: ['My.Component.Dependency'], myProperty: true, myMethod: function() { //... this.callParent(arguments); }, statics: { staticMethod: function() { //... } } });
Olga Petrova, @tyoushe Ext JS Config Properties Ext.define('My.own.Component', { extend:
'Ext.Component‘, config: { myConfig: 'My Text' }, applyMyConfig: function(newTitle, oldTitle) { //implement validation return newTitle; }, updateMyConfig: function(newTitle, oldTitle) { //implement side effects } });
Olga Petrova, @tyoushe Ext JS Overrides var MyComponent = new
Ext.Component({}); Ext.override(MyComponent, { myProperty: 'My Text', myMethod: function () { //... } });
Olga Petrova, @tyoushe Ext JS Mixins Ext.define('Mixin‘, { processData: function(data)
{ /**/ } }); Ext.define('MyComponent‘, { mixins: { myMixin: 'Mixin' }, processData: function(data) { //... this.mixins.myMixin.processData.call(this); } });
Olga Petrova, @tyoushe 10K CUSTOMERS WORLDWIDE 2M SENCHA DEVS WORLDWIDE
7.2M PRODUCT DOWNLOADS 500K ACTIVE FORUM MEMBERS 60% of Fortune 100 Companies Rely on Sencha
Olga Petrova, @tyoushe
Olga Petrova, @tyoushe ECMAScript6 Class system
Olga Petrova, @tyoushe
Olga Petrova, @tyoushe
Olga Petrova, @tyoushe
Olga Petrova, @tyoushe ECMAScript6 Class Systems ✔ Inheritance ✔ Dependencies
✔ Build tool ❌ Config properties ❌ Mixins ❌ Overrides
Olga Petrova, @tyoushe
Olga Petrova, @tyoushe + =
Olga Petrova, @tyoushe + =
Olga Petrova, @tyoushe
Olga Petrova, @tyoushe Decorator pattern is a design pattern that
allows behavior to be added to an individual object, dynamically, without affecting the behavior of other objects from the same class
Olga Petrova, @tyoushe JavaScript Decorators
Olga Petrova, @tyoushe @wrap Method class C { @wrap(f) method()
{ } } class C { method() { } } C.prototype.method = f(C.prototype.method); =>
Olga Petrova, @tyoushe @wrap Class @wrap(f) class C { }
class C { } C = f(C); =>
Olga Petrova, @tyoushe JavaScript Class Fields
Olga Petrova, @tyoushe Class Fields class MyComponent { myField =
42; }
Olga Petrova, @tyoushe ECMAScript 6 to Ext JS Class Systems
✔ Inheritance ✔ Dependencies ✔ Build tool ✔ Config properties @define for class & @config for class fields ✔ Mixins @define for class ✔ Overrides @override for class
Olga Petrova, @tyoushe Class @define({ prototype: { myProperty: "My text"
}, static: { myStaticProperty: 42 } }) class MyOwnComponent extends Component { // }
Olga Petrova, @tyoushe Configs @define class MyOwnComponent extends Component {
@config('nullify') myConfig = 42; applyMyConfig (value, oldValue) { //validation return value; } updateMyConfig (value, oldValue) { //side effects } }
Olga Petrova, @tyoushe Mixins @define class Mixin extends Base {
processData (data) {...} } @define({ mixins: [ Mixin ] }) class MyComponent extends Component { @junction processData (data) { super.processData(data); } }
Olga Petrova, @tyoushe Overrides class MyComponent extends Component {} @override(MyComponent)
class MyComponentOverride { myProperty = ‘My Text’; myMethod () { //... } }
Olga Petrova, @tyoushe Life-cycle Methods class MyComponent extends Component {
ctor () { // do constructor-like things } setup() { // finalize configuration } dtor () { // do destructor-like things } }
Olga Petrova, @tyoushe Lessons Learned
Olga Petrova, @tyoushe Follow Standards if You Can
Olga Petrova, @tyoushe Estimate Effort on Re-write
Olga Petrova, @tyoushe Encapsulate
Olga Petrova, @tyoushe Keep your Eyes on New Standards
Olga Petrova, @tyoushe Start to Adapt Earlier
Olga Petrova, @tyoushe Keep Decorator/Adapter/Facade Patterns in Mind
Olga Petrova, @tyoushe 3