JavaScript: the Big Picture

Similar documents
Events & Callbacks (ESaaS 6.5)! 2013 Armando Fox & David Patterson, all rights reserved

Client vs Server Scripting

Why Discuss JavaScript? CS312: Programming Languages. Lecture 21: JavaScript. JavaScript Target. What s a Scripting Language?

CS312: Programming Languages. Lecture 21: JavaScript

JavaScript: the language of browser interactions. Claudia Hauff TI1506: Web and Database Technology

Etanova Enterprise Solutions

JavaScript. What s wrong with JavaScript?

JavaScript CS 4640 Programming Languages for Web Applications

JavaScript CS 4640 Programming Languages for Web Applications

Java SE7 Fundamentals

This course is designed for web developers that want to learn HTML5, CSS3, JavaScript and jquery.

Working with Javascript Building Responsive Library apps

The course is supplemented by numerous hands-on labs that help attendees reinforce their theoretical knowledge of the learned material.

User Interaction: jquery

JavaScript Programming

Scripting. Web Architecture and Information Management [./] Spring 2009 INFO (CCN 42509) Contents

Pro JavaScript. Development. Coding, Capabilities, and Tooling. Den Odell. Apress"

Using Development Tools to Examine Webpages

JavaScript Specialist v2.0 Exam 1D0-735

JavaScript: Sort of a Big Deal,

The course also includes an overview of some of the most popular frameworks that you will most likely encounter in your real work environments.

CS50 Quiz Review. November 13, 2017

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)

INF5750. Introduction to JavaScript and Node.js

AJAX Workshop. Karen A. Coombs University of Houston Libraries Jason A. Clark Montana State University Libraries

JavaScript Patterns O'REILLY* S toy an Stefanov. Sebastopol. Cambridge. Tokyo. Beijing. Farnham K8ln

Front End Nanodegree Syllabus

Advance Mobile& Web Application development using Angular and Native Script

Tooling for Ajax-Based Development. Craig R. McClanahan Senior Staff Engineer Sun Microsystems, Inc.

a Very Short Introduction to AngularJS

AJAX Programming Overview. Introduction. Overview

Modern Web Application Development. Sam Hogarth

Frontend II: Javascript and DOM Programming. Wednesday, January 7, 15

JavaScript. History. Adding JavaScript to a page. CS144: Web Applications

JavaScript. History. Adding JavaScript to a page. CS144: Web Applications

Outline. AJAX for Libraries. Jason A. Clark Head of Digital Access and Web Services Montana State University Libraries

729G26 Interaction Programming. Lecture 4

Web UI. Survey of Front End Technologies. Web Challenges and Constraints. Desktop and mobile devices. Highly variable runtime environment

Copyright Descriptor Systems, Course materials may not be reproduced in whole or in part without prior written consent of Joel Barnum

COURSE 20480B: PROGRAMMING IN HTML5 WITH JAVASCRIPT AND CSS3

JavaScript. The Bad Parts. Patrick Behr

Index. C CakePHP framework, 232 Cascading Style Sheets (CSS)

welcome to BOILERCAMP HOW TO WEB DEV

Programming in HTML5 with JavaScript and CSS3

Front-End Web Developer Nanodegree Syllabus

Welcome to CS50 section! This is Week 10 :(

JavaScript for PHP Developers

20480C: Programming in HTML5 with JavaScript and CSS3. Course Code: 20480C; Duration: 5 days; Instructor-led. JavaScript code.

Varargs Training & Software Development Centre Private Limited, Module: HTML5, CSS3 & JavaScript

IN Development in Platform Ecosystems Lecture 2: HTML, CSS, JavaScript

Part of this connection identifies how the response can / should be provided to the client code via the use of a callback routine.

8/19/2018. Web Development & Design Foundations with HTML5. Learning Objectives (1 of 2) Learning Objectives (2 of 2) What is JavaScript?

CL_55244 JavaScript for Developers

Front End Nanodegree Syllabus

Programming the World Wide Web by Robert W. Sebesta

Full Stack Web Developer

Advanced JavaScript. Konstantin Käfer. Konstantin Käfer

Course 20480: Programming in HTML5 with JavaScript and CSS3

Introduction to JavaScript p. 1 JavaScript Myths p. 2 Versions of JavaScript p. 2 Client-Side JavaScript p. 3 JavaScript in Other Contexts p.

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)

jquery with Fundamentals of JavaScript Training

Backend Development. SWE 432, Fall Web Application Development

Web Development. with Bootstrap, PHP & WordPress

Basics of JavaScript. Last Week. Needs for Programming Capability. Browser as Development Platform. Using Client-side JavaScript. Origin of JavaScript

Index. Ray Nicholus 2016 R. Nicholus, Beyond jquery, DOI /

(Refer Slide Time: 01:40)

Frontend UI Training. Whats App :

Standard 1 The student will author web pages using the HyperText Markup Language (HTML)

Towards Improving the Reliability of JavaScript-based Web 2.0 Applications

Lesson 12: JavaScript and AJAX

Courslets, a golf improvement web service. Peter Battaglia

Elementary Computing CSC 100. M. Cheng, Computer Science

CISC 1600 Lecture 2.4 Introduction to JavaScript

When learning coding, be brave

UI Course HTML: (Html, CSS, JavaScript, JQuery, Bootstrap, AngularJS) Introduction. The World Wide Web (WWW) and history of HTML

Fast Mobile UIs. You re an Edge Case. Thursday, 8 March, 12

widgetjs Documentation

Sample CS 142 Midterm Examination

Today. Continue our very basic intro to JavaScript. Lambda calculus

JavaScript: The Good Parts

JavaScript: The Definitive Guide

CGS 3066: Spring 2015 JavaScript Reference

Financial. AngularJS. AngularJS.

20480B - Version: 1. Programming in HTML5 with JavaScript and CSS3

JavaScript By: A. Mousavi & P. Broomhead SERG, School of Engineering Design, Brunel University, UK

Javascript. Many examples from Kyle Simpson: Scope and Closures

Module 5 JavaScript, AJAX, and jquery. Module 5. Module 5 Contains an Individual and Group component

Financial. AngularJS. AngularJS. Download Full Version :

Notes on JavaScript (aka ECMAScript) and the DOM

20480B: Programming in HTML5 with JavaScript and CSS3

COURSE OUTLINE MOC 20480: PROGRAMMING IN HTML5 WITH JAVASCRIPT AND CSS3


JavaScript: Introduction, Types

JavaScript: The Good Parts. Douglas Crockford Yahoo! Inc.

AJAX: Asynchronous Event Handling Sunnie Chung

Client Side JavaScript and AJAX

Assignment: Seminole Movie Connection

Web Development. HCID 520 User Interface Software & Technology

Static Webpage Development

Contents. Demos folder: Demos\14-Ajax. 1. Overview of Ajax. 2. Using Ajax directly. 3. jquery and Ajax. 4. Consuming RESTful services

Transcription:

JavaScript had to look like Java only less so be Java's dumb kid brother or boy-hostage sidekick. Plus, I had to be done in ten days or something worse than JavaScript would have happened.! JavaScript: the Big Picture (ESaaS 6.1)! 2013 Armando Fox & David Patterson, all rights reserved Image: Wikimedia. Used under CC-SA license.

What moving parts are involved in creating the rich interactive user experiences that characterize JavaScript-intensive sites?! What minimal set of key concepts explains how this works, and which of those concepts do we already know from Ruby/ Rails/SaaS architecture?!

Subjective bias disclaimer# JavaScript doesn t (fully) deserve its bad reputation# ESaaS takes principled and noncondescending approach to JS# jquery is the way to do client-side JS# Jasmine/TDD just as important for JS as for server# Jury still out on server-side JS# 3#

History# 1995: Netscape includes LiveScript JavaScript as browser scripting language# Originally, for simple client-side code such as animations and form input validation# Document Object Model (DOM) lets JavaScript inspect & modify document elements# 1997: standardized as ECMAScript# 1998: Microsoft adds XmlHttpRequest to IE5# 2005: Google Maps, AJAX takes off #

Use cases for JS today# Enhance client part of SaaS-centric app# Single-page apps # Pivotal Tracker: still heavy server support# Sudoku: minimal or no server support# Standalone rich client apps (Google Docs)# Server-side apps (Node.js)#

Graceful degradation for SaaS-centric apps# Browsers with JS disabled ( legacy browsers ) should get a usable experience# should be easy if your app is RESTful already# Conditionally show page elements that require JS# Add elements in a "setup" function in JS# Or, make elements hidden using CSS, then change CSS style in "setup" function#

DOM & JavaScript: Document = tree of objects# DOM is a language-independent, hierarchical representation of HTML or XML document# Browser parses HTML or XML => DOM# JavaScript API (JSAPI) makes DOM data structures accessible from JS code# Inspect DOM element values/attributes# Change values/attributes redisplay# Implemented incompatibly across browsers but jquery framework will help us# JavaScript is just another language; the JSAPI gives it power to script the browser.! JavaScript is a single-threaded language. Therefore all JS interactions with browser must be nonblocking.!

Summary: JavaScript s privileged position# Because it s embedded in browser, JavaScript code can:# 1. be triggered by user-initiated events (mouse down, mouse hover, keypress, )# 2. make HTTP requests to server without triggering page reload# 3. be triggered by network events (e.g. server responds to HTTP request)# 4. examine & modify (causing redisplay) current document#

Client-side JavaScript code can interact with HTML page elements because this functionality: (a) is part of the JavaScript language (b) is part of the browser (c) is provided by the JSAPI (a), (b) and (c) (a) & (b) only (b) & (c) only (a) only 9#

Client-Side JavaScript for Ruby Programmers (ESaaS 6.2)! 2013 Armando Fox & David Patterson, all rights reserved

JavaScript basics# Interpreted, dynamically typed# No classes; prototypal inheritance instead (later)# Basic object type is a hash; keys sometimes called slots or properties var movie={title: 'Up', "releaseinfo": {rating: 'G', year: 2010}} Slot names can always be in quotes; OK to omit if slot name is also a legal JS variable name# Use JavaScript console window in modern browsers to try things interactively#

Variable Scope# var restricts scope of a variable; if absent or used in outermost scope => global (almost never what you want!)# Functions are 1 st class objects and closures! extremely common: passing functions to functions# extremely common: functions as property values (feels like instance methods, though they aren t really)# Best practice: create a single global variable that is an object whose properties are your functions & attributes# 12#

JS, browsers, and scope# The global object defines some constants that are part of JS s runtime environment# this in global scope refers to global object# Each HTML page gets its own JS global object# So each page must separately load any desired JS: = javascript_include_tag 'application' (usually in application.html.haml) <script src="/public/javascripts/application.js"> </script> Why use helper vs explicit tag? asset pipeline Best practice: JS code in multiple separate files#

Beautiful JavaScript?# Use what you already know:! SOFA guidelines# Keep code separate from HTML# Red Green Refactor with Jasmine# Tools that can help further:! JavaScript, The Good Parts (Crockford)# JSLint command-line tool jsl JSHint.com# CodeClimate now supports JavaScript!# 14#

If you manually open two separate browser windows, can JavaScript code loaded into one of those windows affect the other window?# 1. Depends on the browser implementation 2. Yes, because JavaScript can access the DOM via the JSAPI 3. No, because each window has its own global object and therefore its own copy of the interpreter 4. No, because there is no concurrency in JavaScript (only one thread can run at a time) 15#

Optional aside# Another RESTful front end for ugly website# http://pastebin.com/lbhcktrf

Functions (ESaaS 6.3)! 2013 Armando Fox & David Patterson, all rights reserved

Functions are closures# Functions are first class objects & closures! A function is a lambda expression# var make_times = function(mul) { return function(arg) { return arg * mul; } } // or: function make_times(mul) {... } times2 = make_times(2) times3 = make_times(3) times2(5) 10 times3.call(null, 5) 15

Functions as properties# RP = {}; RP.setup = function() { // add invisible 'div' to end of page: }; RP.getMovieInfo = function() { // etc. }; RP = { setup: function() { // add invisible 'div' to end of page: }, getmovieinfo: function() { // etc. } } 19#

Which is NOT true about functions in JavaScript? They can be anonymous They always return a value, even if that value might be undefined They can be passed a function as an argument They can execute concurrently with other functions 20#

Constructor-style Functions (ESaaS 6.3)! 2013 Armando Fox & David Patterson, all rights reserved

Apple Newton (c. 1997)#

Every object has a prototype# No Classes; object inheritance based on prototypes # each newly-created object has a prototype# obj. proto (except in some versions of IE)# when slot lookup fails in an object, its prototype is consulted, and so on up the chain# so object inherits both value-slots and function-slots# Prototypal inheritance or differential inheritance!

Constructor style functions a/k/a JS s single worst design flaw# Call a function using new creates new object (this) whose prototype is whatever the function s prototype is, and returns it# Call a function on that object this is bound to that object (receiver)# Call a function without a receiver this assumed to be Global Object, window Call a constructor-like function without new return value is undefined# http://pastebin.com/srnevh59

var Square = function(side) { this.side = side; this.area = function() { return this.side*this.side; } }; Which call will evaluate to 9?# Square(3).area Square(3).area() (new Square(3)).area var p = Square ; (new p(3)).area() 25#

The Document Object Model (DOM) & jquery (ESaaS 6.4)! 2013 Armando Fox & David Patterson, all rights reserved

DOM Example# <p id="notice"> This is your <span class="warn">last</span> chance! </p> e = document.getelementbyid('notice)'; e.childnodes text! nodevalue: this is your # element p! attributes: { id: 'notice' }# element span! attributes: { class: 'warn' }# text! nodevalue: last # text! nodevalue: # chance #

jquery# A powerful framework for DOM manipulation# adds many useful features over browsers builtin JSAPI# homogenizes incompatible JSAPI s across browsers# Don t forget to load it on every page??! Rails 3 includes by default, or load from Google# Defines a single polymorphic global function jquery(), aliased as $() Four ways to call it keep them straight!#

Way #1 & #2: Select DOM elements, create elements# $() or jquery() with any CSS3 expression# $('#movies'), $('.heading'), $('table') Warning! document.getelementbyid() Equivalent: $(window.document).find(selector) Warning! may return multiple elements, but it s not necessarily a JavaScript array! # but there is an iterator for it# Way #2: Create element var newdiv = $('<div class="main"></div>'); Resulting elements have jquery superpowers!#

Engineering Software as a Service, Fig 6.8 30#

When using JavaScript for client-side form validation, which is NOT true? JavaScript code can inspect DOM element attributes to see what the user typed JavaScript code can prevent the "Submit" button from submitting the form Some validations may be impractical to perform on client, so must be done on server The server doesn t have to repeat the validations performed by JavaScript 31#