
Modern Web UIs Design and Implementation with JavaScript Examples
Explore software design and implementation concepts in CSE 331 with a focus on modern web user interfaces. Learn about dynamic web content, JavaScript modules, GUI application structures, and more. Understand the challenges in writing applications like Gmail and discover solutions for creating modular and maintainable code. Dive into coding examples and improve your skills in creating dynamic and interactive web interfaces.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
CSE 331 Software Design & Implementation Kevin Zatloukal Spring 2021 Modern Web UIs
Recall from last time let obj1 = { a: 2, f: function (x) { return x + this.a } }; let obj2 = { a: 1, f: function (x) { return x this.a } }; // 4 console.log(obj1.f(2)); console.log(obj2.f(2)); // 1 CSE 331 Spring 2021 2
Recall from last time let obj1 = { a: 2, f: function (x) { return x + this.a } }; let obj2 = { a: 1, f: function (x) { return x this.a } }; // 4 // 3 console.log(obj1.f.call(obj1, 2)); console.log(obj1.f.call(obj2, 2)); console.log(obj2.f.call(obj1, 2)); console.log(obj2.f.call(obj2, 2)); // 0 // 1 CSE 331 Spring 2021 3
Recall from last time let obj1 = { a: 2, f: function (x) { return x + this.a } }; let obj2 = { a: 1, f: function (x) { return x this.a } }; let f = obj1.f; console.log(f(2)); // NaN let f = obj1.f.bind(obj1); console.log(f(2)); // 4 CSE 331 Spring 2021 4
Dynamic Web Content Earlier example had a fixed set of components. same for iPhone / Android apps More realistic apps need to change the set of components displayed on the screen dynamically consider Gmail as an example need the components to come from code CSE 331 Spring 2021 5
JS Example register-js/index.js CSE 331 Spring 2021 6
Structure of GUI Application Listeners updates events GUI Model Components presentation (provided by library) data and invariants CSE 331 Spring 2021 7
Problems These tools can be used to write Gmail But it has a number of problems 1. Lack of tool support no checking of types, tags, etc. 2. No support for modularity all the code and UI in a single file 3. More boilerplate minimized JS file would change function names need to call btn.addEventListener by hand CSE 331 Spring 2021 8
JS Modules EcmaScript6 (ES6) added support for modules. Each file is a separate unit ( namespace ) Only exported names are visible outside: export function average(x, y) { Others can import using: import { average } from ./filename ; CSE 331 Spring 2021 9
ES6 Example register-js2/ CSE 331 Spring 2021 10
JS Classes ES6 added new syntax for classes: class Foo { constructor(val) { this.secretVal = val; } secretMethod(val) { return val + this.secretVal; } } CSE 331 Spring 2021 11
More from ES6 Example register-js2/ CSE 331 Spring 2021 12
JS vs Java Classes JS method signatures are just the name JS objects are just HashMaps field names are the keys obj.avg(3, 5) Java methods signatures are name + arg types e.g., avg(int,int) JS has only one method with a given name language allows different numbers of arguments missing arguments are undefined can strengthen a spec by accepting a wider set of possible input types CSE 331 Spring 2021 13
Problems These tools can be used to write Gmail But it has a number of problems 1. Lack of tool support no checking of types, tags, etc. 2. No support for modularity all the code and UI in a single file 3. More boilerplate minimized JS file would change function names need to call btn.addEventListener by hand CSE 331 Spring 2021 14
TypeScript Adds type constraints to the code: arguments and variables let x : number = 0; fields of classes quarter: string; tsc performs type checking Creates version has type annotations removed CSE 331 Spring 2021 15
TypeScript Types Basics from JavaScript: number, string, boolean, string[], Object But also specific classes Foo tuples: [string, int] enums (as in Java) allows null to be included or excluded (unlike Java) any type allows any value CSE 331 Spring 2021 16
TypeScript Example register-ts/ CSE 331 Spring 2021 17
TypeScript Type system is unsound can t promise to find prevent all errors can be turned off at any point with any types x as Foo is an unchecked cast to Foo x! casts to non-null version of the type (useful!) Full description of the language at typescriptlang.org CSE 331 Spring 2021 18