liveBook · Manning

JavaScript

As explained in Web Components in Action

JavaScript is a programming language standardized as ECMAScript and commonly executed in web browsers.

JavaScript drives browser components by combining data, template literals, and functions that generate HTML. A component can pass structured choices into a template, then render menus and other markup from those choices. section 6.4

A practical JavaScript workflow for browser components includes:

  • Use template literals to mix ordinary markup, variables, and function results in one HTML string. section 6.8
  • Adapt newer JavaScript for older browsers by transpiling ES2015 features into ES5 output with Babel. section 12.5

A data-driven business card

A business-card component receives backgroundChoices and logoChoices arrays. Its template calls an options function for each array, producing two select menus. Selecting an item lets the component customize its logo and tiled background without duplicating the surrounding markup. section 6.4

Listing 6.10. Calling out to a function-based expression to render our menus
html(p) {
   return `
      <div class="logo-picker">
           Logo: ${this.options(p.logoChoices)}              #1
      </div>
      <div class="background-picker">Background:
           ${this.options(p.backgroundChoices)}</div>        #2
      <div class="biz-card">
       <div class="logo"></div>
       <div class="top-text">
           <h1>${p.first_name} ${p.last_name}</h1>
           <h3>${p.title}</h3>
       </div>

       <div class="bottom-text">
           <h3>phone: ${p.phone}</h3>
           <h3>${p.email} / ${p.website}</h3>
       </div>
   </div>`;
},

Inspect the template-literal listing to see how JavaScript calls a reusable options function from HTML generation. section 6.4

How Web Components in Action covers it

How deep it goes
Explains template literals, interpolation, array-based generation, and transpilation workflows, but defers broader build-process details.
Examples
Demonstrates a customizable business card, generated select menus, ES2015 syntax, and separate modern-browser and IE11 builds.
What it assumes
Assumes browser markup and component familiarity while teaching template literals, generated markup, and ES2015 compatibility incrementally.
What you can do after
Build data-driven Web Components and transpile their newer JavaScript syntax for IE11 with Babel.
How it connects
Connects JavaScript with Web Components, template literals, HTML, CSS, Babel, Rollup, polyfills, and browser compatibility.

Also explained in

Compare how 12 books explain JavaScript →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Components in Action. The section links point to the parts of the book it draws on.