Expressive JavaScript: Feature Description

The history of hypertext, the specifics of HTML, CSS, differences in browsers and features of mobile devices have left their mark on the style of Internet programming and especially on the JavaScript language (JS).

The characteristic feature of modern high technology “do not understand, did not” to JS is most directly related. However, this should not be given such a meaning. JS is a wonderful programming language that requires "respect" for itself, and from the programmer - attentiveness and accuracy.

expressive javascript

Before claiming a bug in a language or a problem in a browser, you need to be absolutely sure that the algorithm is flawless, both in terms of syntax and in terms of semantics.

JavaScript Overview

The main area of ​​"habitat" JS - the browser. We can say that its main goal is to serve the page tree - the DOM, but it will not be too complete and accurate. Expressive JavaScript - tasks for the correct display of the page and its proper functioning.

Static pages have long and reasonably been forgotten, and the dynamics of all elements of the site have become the norm. The characteristic tendency of modern ideas is one page, which changes dynamically depending on the behavior of the visitor. This fact is usually not characteristic of CMS (site management systems), which are still a collection of numerous pages that combine PHP, Perl templates, various services APIs, jQuery and other tools.

expressive javascript tasks

Expressive JavaScript occupies its own unique niche. This language is ideally tuned to ensure the functionality of the page, it provides elementary connections between the pages of one site, makes it possible to switch to other sites, load any pages into the browser, and work with various servers.

There is no such event that could not be realized through this language. Almost all popular HTML tags allow you to designate the necessary functionality that expressive JavaScript animates, almost parallel execution. From this follows the cardinal difference between the style of "writing in JS" from other programming languages: there is no, as such, a single algorithm. Expressive JavaScript - solving problems in a special functionally perfect style.

Language Functionality and Page Events

According to the general programming logic, any algorithm in any language is:

  • data description;
  • description of the algorithm.

The first one is traditionally not typical anymore, that is, it is not at all necessary to describe the data before its application, and even, having described the variable, it is not at all necessary to indicate its type.

The second is not always used: the data initialization code and the code that processes them. Expressive JavaScript takes the developer to completely different positions.

The page of the site, getting into the browser, turns into a tree of objects - DOM. Virtually every DOM object (i.e., page) can be assigned an event. Formally, the page turns into a composition:

  • objects;
  • events;
  • JS functions.

Since a page is always a semantically finished element of a web resource, the events that trigger the elements (objects) of this page transfer the implementation of a specific meaning (specific action) to JavaScript algorithms (functions).

expressive javascript problem solving

In fact, the page in the hands of an experienced developer is a transfer of meaning into functionality. Page elements are able to implement themselves through JavaScript functions.

What and when to execute: simple option

When expressive JavaScript is limited by its own capabilities, the developer can compose the functionality of the page as a description of the data or a description of the initialization code.

The developer can only guess the visitor’s behavior plan, but is not obliged to think over and implement the exact algorithm of his behavior. The idea of ​​imposing a dialogue is now exclusively in the field of competence of “intrusive advertising”, and not a professionally executed page.

expressive javascript reviews

Abstracting from the problem of organizing a dialogue, concentrating on the distribution of functionality within the meaning of the page elements, expressive JavaScript reviews, opinions and actions of the client translate into his sphere of competence. The point here is that the behavior of the user on the page should be equivalent to his behavior in a real situation: at home, at work, on the street, etc.

A simple option demonstrates the inherent power of JavaScript. This language not only provides parallel execution of the functional, but also guarantees its compatibility over time. The syntax of the language provides the developer with the ability to write safe, working code, regardless of the time when it will be required to be executed.

Functionality Change: Server Involvement

The semantics of the page and its functionality are changed by the server, that is, the visitor’s actions cause changes to the page elements in such a way that one function is replaced by another.

In this situation, the developer combines the capabilities of the server language with the capabilities of JS. This gives him the opportunity to offer the visitor a multivariate movement: the page responds adequately to human behavior, as in a dialogue with a similar one.

expressive javascript book

At the initial stage, the page has one semantics. After selecting the desired direction, the visitor receives an updated version of the page, proceeds to the next stage, gets new opportunities. In this context, the site can accumulate information about how visitors behave, adapt to appropriate behavior, transferring the “actual work algorithm” of some visitors to the work of others.

Simply put, expressive JavaScript, acting in conjunction with a server-side programming language, gets the ability to dynamically adapt to the desired functionality.

JavaScript and server language objects

The page is in the browser until the visitor leaves the site: JavaScript objects are constantly active. The server language object “lives” while the page is being formed, the AJAX request is processed, or another action is performed under the control of the server language.

JavaScript objects are always operational, server-side language objects are not. The latter unfolds its system of objects, receiving control, and does this systematically, repeating itself many times, doing unnecessary work.

Activity of JS objects and server language

The best solution is to move the center of gravity to the browser side. This reduces the load on the server and makes it possible to design permanently existing objects, rather than repeatedly forming them on the server.

There is a sufficient number of interesting publications to help developers, the best of which is the second edition of “Expressive JavaScript, Eloquent Javascript,” by Marijn Haverbeke, translated by Vyacheslav Golovanov.

The book is written in an accessible style, contains a large number of examples and tasks, the own solution of which can be checked by the attached links on the Internet. Examples and tasks from this book are systematized by topics, application features. Various coding options are considered in detail.

Functionality dynamics and code security

The copyright problem of the code (algorithm) in JavaScript, against the code (algorithm) in the server language, with a cursory analysis, of course, exists. Everything that got into the browser is available for viewing and unauthorized copying.

If the object in the browser changes dynamically under the control of the server, then not everything is so bad. It is not necessary to make a page of static content of the required functionality.

Functionality dynamics and code security

Functionality can and should change accordingly to the behavior of the visitor. By distributing functionality through the stages of a dialogue with a visitor, you can simply close the possibility of unauthorized stealing the code.

The question of how to solve such a problem depends on the scope of the site and the qualifications of the developer. But this question always makes sense to pose, and it is available for solution.


All Articles