Missed JavaScript Days 2026? The Replays Are Now Available – Watch Now!

Ext JS and ES2015/6/7 – Modernizing the Ext JS Class System

October 25, 2016 3844 Views

Get a summary of this article:

Show

SenchaCon 2016

The JavaScript language today is hardly recognizable when compared to the JavaScript of a few short years ago. The changes range from small pieces of syntax (such as loops, variables, and functions), up to the level of classes for creating coherent functional units and extend all the way to connecting these pieces into applications via modules.

Today, through the widespread use of tools such as Babel, Traceur, webpack, and others, many developers have embraced these new language features and their code can still run on “those” browsers.

In my session at SenchaCon 2016 (Ext JS and ES2015/6/7 – Modernizing the Ext JS Class System), we’ll talk about how this evolution in language and tools affects the applications we write using Ext JS. We’ll look at how the class keyword compares with Ext.define, and how class names line up with modules. And we’ll compare the two end-states of an upgraded application: one with minimal changes to existing code and one that fully embraces all of the new language features.

Don’t have your ticket yet for SenchaCon 2016? Register today.

You can try the new and updated features of Javascript Web Framework which help to modernize your team and apply modern techniques when building applications.

Sneak Peak

Class Declarations

Let’s take a simple utility class that might be found in an Ext JS application today and see what an upgrade might look like.

    Ext.define('App.util.Foo', {
        extend: 'App.some.Base',
        mixins: 'Ext.mixin.Observable',

        config: {
            value: null
        }

        constructor: function (config) {
            this.mixins.observable.constructor.call(this, config);
        },

        updateValue: function (value, oldValue) {
            this.fireEvent('valuechange', value, oldValue);
        }
    });

The following diagram shows the important pieces produced by the code above:

Class Declarations part 1

If you look at the constructor property on the prototype, you’ll see that it points to the method we passed to Ext.define. This approach, while flexible, is not compatible with the new class keyword. Using the class keyword produces the following, immutable relationship:

    App.util.Foo === App.util.Foo.prototype.constructor

Minimal Upgrade

The minimal upgrade requires us to rename the “constructor” method to avoid this conflict. The new name is simply “construct“:

    Ext.define('App.util.Foo', {
        extend: 'App.some.Base',
        mixins: 'Ext.mixin.Observable',

        config: {
            value: null
        }

        construct (config) {
            this.mixins.observable.construct.call(this, config);
        },

        updateValue (value, oldValue) {
            this.fireEvent('valuechange', value, oldValue);
        }
    });

Though not necessary, we’ve also taken advantage of the new function property syntax for object literals and removed the “: function” from our methods.

Because the new Ext.define internally produces a standard class, we gain some benefits as well. Consider the following diagram showing what is generated by the upgraded Ext.define call above:

Class Declarations part 2

Because class constructors are now prototype-chained to their superclass constructors, effectively all static members are inheritableStatics for free!

Maximum Upgrade

At the opposite end of the upgrade continuum is a complete upgrade to all the new language features and options. Let’s look at what the fully upgraded version of the above class might look like:

    import { define }     from 'extjs-kernel'; // module names not final
    import { Observable } from 'extjs-core';

    import { Base }       from 'app-some';

    @define({
        mixins: Observable,
        config: {
            value: null
        }
    })
    export default class Foo extends Base {
        updateValue (value, oldValue) {
            this.fireEvent('valuechange', value, oldValue);
        }
    }

In this version, we’re taking advantage of several new class system features as well as some upcoming JavaScript features.

If you haven’t seen the @define syntax before it’s called a decorator, and it’s an exciting language feature currently being worked through the standardization process. It’s available today via the magic of transpilers. Transpilers are tools that compile JavaScript-to-JavaScript or more precisely, Advanced-JavaScript-to-Browser-Friendly-JavaScript. Through the @define decorator, you can apply all the additional powers of the Ext JS class system to this standard class.

We also removed the construct/constructor methods in this example. This is because the construct method of Ext.Base now provides a Common Object Lifecycle. When called with a single object parameter or if the class uses the Config System, the necessary steps to initialize the instance are handled automatically.

Last, we’re using the new, standard import and export keywords. Support for these is also by virtue of transpilers (because no browser yet supports them). To learn more of the details, you can also attend Ross Gerbasi’s talk: The Modern Toolchain.

Choices, Choices

Because there is no one-size-fits-all approach, the overarching goal of this upgrade is to minimize what must be done to existing code while at the same time enabling developers to usefully modernize JavaScript techniques and practices.

To hear first-hand what else is coming, be sure to attend my session at SenchaCon 2016!

Author

Don Griffin

Don is the Sr. Engineering Director for Ext JS. He was an Ext JS user for 2 years before joining Sencha and has more than 25 years of software engineering experience on a broad range of platforms. His experience includes designing web application front-ends and back-ends, native GUI applications, network protocols and device drivers. Don’s passion is to build world class products that people love to use.

Recommended Articles

How to Use Tailwind CSS v4 in Ext JS (Classic) Without Breaking the Theme

We know that Ext JS is a war tank. When it comes to handling absurd volumes of data and complex front-end architectures, few frameworks come…

How to Use the Ext JS Grid in React: Setup, Columns, Editing and Grouping

Set up the Ext JS grid in React with ReExt, then add typed columns, store-backed data, inline editing, grouping and summaries. Full code included. The…

Understanding Ext JS Layouts and Containers: An Introduction (Classic vs. Modern)

Building complex, responsive, and data-intensive Web applications requires a solid layout engine. In Ext JS, the layout system is the backbone of your Application UI.…

AI-Driven Test Grading with Ext JS, Node.js, and OpenAI: A Secure Enterprise Architecture

Learn how to build an AI-driven test grading system with Ext JS, Node.js, MySQL, and OpenAI using secure API architecture, deterministic scoring, and human oversight.…

Sencha AI Just Got a Lot Bigger: One Chatbot, Every Sencha Product

Sencha’s AI assistant has grown from a focused Ext JS helper into a product-aware chatbot covering the whole Sencha suite. Here’s what’s new and why…

Building High-Performance Real-Time Operational Dashboards with Ext JS and React

Real-time operational dashboards are no longer simply reporting interfaces. In logistics, fleet management, supply chain operations, financial services, and other data-intensive environments, they are part…

View More