Lecture 8 (7.5?): Javascript

Similar documents
needs to be reliable, easy to change, retarget efficiency is secondary implemented as interpreter, with virtual machine

1993: renamed "Java"; use in a browser instead of a microwave : Sun sues Microsoft multiple times over Java

CS312: Programming Languages. Lecture 21: JavaScript

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

JavaScript CS 4640 Programming Languages for Web Applications

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

CGS 3066: Spring 2015 JavaScript Reference

JavaScript CS 4640 Programming Languages for Web Applications


CSC Web Technologies, Spring Web Data Exchange Formats

CSC Web Programming. Introduction to JavaScript

JavaScript Programming

Client-Side Web Technologies. JavaScript Part I

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

JavaScript Specialist v2.0 Exam 1D0-735

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

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 Lecture 1

So, if you receive data from a server, in JSON format, you can use it like any other JavaScript object.

CSC 337. JavaScript Object Notation (JSON) Rick Mercer

FALL 2017 CS 498RK JAVASCRIPT. Fashionable and Functional!

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

This tutorial will help you understand JSON and its use within various programming languages such as PHP, PERL, Python, Ruby, Java, etc.

JavaScript for PHP Developers

Background. Javascript is not related to Java in anyway other than trying to get some free publicity

INF5750. Introduction to JavaScript and Node.js

Lecture 3: The Basics of JavaScript. Background. Needs for Programming Capability. Origin of JavaScript. Using Client-side JavaScript

Working with JavaScript

JSON is a light-weight alternative to XML for data-interchange JSON = JavaScript Object Notation

Such JavaScript Very Wow

Kyle Rainville Littleton Coin Company

Pace University. Fundamental Concepts of CS121 1

CISC 1600 Lecture 2.4 Introduction to JavaScript

JavaScript Introduction

JSON as an XML Alternative. JSON is a light-weight alternative to XML for datainterchange

Working with Database. Client-server sides AJAX JSON Data formats Working with JSON data Request Response Bytes Database

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

JavaScript. What s wrong with JavaScript?

Web technologies. Web. basic components. embellishments in browser. DOM (document object model)

Javascript. Many examples from Kyle Simpson: Scope and Closures

Part 1: jquery & History of DOM Scripting

Node.js Training JavaScript. Richard richardrodger.com

REST. Web-based APIs

UNIT -II. Language-History and Versions Introduction JavaScript in Perspective-

Documents and computation. Introduction to JavaScript. JavaScript vs. Java Applet. Myths. JavaScript. Standard

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

8/19/2018. Web Development & Design Foundations with HTML5. Learning Objectives (1 of 2) Learning Objectives (2 of 2) Helper Applications & Plug-Ins

Programming language components

ECMAScript 2015 and beyond The Future of JavaScript is Now!

JavaScript: The Basics

AJAX. Lab. de Bases de Dados e Aplicações Web MIEIC, FEUP 2010/11. Sérgio Nunes

Javascript, Java, Flash, Silverlight, HTML5 (animation, audio/video, ) Ajax (asynchronous Javascript and XML)

Chapter 1 Introduction to Computers and the Internet

JavaScript I Language Basics

Welcome to CS50 section! This is Week 10 :(

a Why JavaScript? jonkv interactivity on the web CGI JavaScript Java Applets Netscape LiveScript JavaScript 1: Example

The JavaScript Language

A.A. 2008/09. Why introduce JavaScript. G. Cecchetti Internet Software Technologies

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

COMP284 Scripting Languages Lecture 14: JavaScript (Part 1) Handouts

Boot Camp JavaScript Sioux, March 31, 2011

JavaScript: the Big Picture

Lesson 12: JavaScript and AJAX

Web Application Development

TIME SCHEDULE MODULE TOPICS PERIODS. HTML Document Object Model (DOM) and javascript Object Notation (JSON)

Parsing Scheme (+ (* 2 3) 1) * 1

AJAX ASYNCHRONOUS JAVASCRIPT AND XML. Laura Farinetti - DAUIN

Java Programming Basics. COMP 401, Spring 2017 Lecture 2

SEEM4570 System Design and Implementation Lecture 03 JavaScript

<form>. input elements. </form>

Treating Framework Fatigue With JavaScript

JavaScript: Sort of a Big Deal,

10.1 Overview of Ajax

A synchronous J avascript A nd X ml

Programming with Java

Spring JavaScript. John Mitchell Adapted by Mooly Sagiv. Reading: links on last slide Homework 1: 18/3 17/4

CMU MSP 36601: Computer Hardware and Data Representation

2 rd class Department of Programming. OOP with Java Programming

ECMAScript 2015 The Future of JavaScript is Now!

Overview: Programming Concepts. Programming Concepts. Names, Values, And Variables

Overview: Programming Concepts. Programming Concepts. Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript

/ Introduction to XML

developed ~2007 by Robert Griesemer, Rob Pike, Ken Thompson open source

What is PHP? [1] Figure 1 [1]

Values and Variables 1 / 30


3 The Building Blocks: Data Types, Literals, and Variables

AJAX: Rich Internet Applications

Chapter 2: Functions and Control Structures

Java Identifiers. Java Language Essentials. Java Keywords. Java Applications have Class. Slide Set 2: Java Essentials. Copyright 2012 R.M.

Python source materials

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

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018

Comprehensive AngularJS Programming (5 Days)

Outline. Introduction to JavaScript Resources What is JavaScript? JavaScript in web pages

Lecture 5: Python PYTHON

Chapter 2: Using Data

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

JAVASCRIPT FOR PROGRAMMERS

,

Transcription:

Lecture 8 (7.5?): Javascript

Dynamic web interfaces forms are a limited interface <FORM METHOD=GET ACTION="http://bwk.mycpanel.princeton.edu/cgi-bin/hello1.cgi"> <INPUT TYPE="submit" value="hello" > </FORM> limited interaction on client side e.g., Javascript for simple validation form data sent to server for processing synchronous exchange with server potentially slow: client blocks waiting for response recreates entire page with what comes back even if it's mostly identical to current content making web interfaces more interactive and responsive "dynamic HTML": HTML + CSS, DOM, Javascript asynchronous partial update: XMLHttpRequest / Ajax plugins like Flash, Silverlight, Quicktime,... HTML5 (reduces need for plugins)

Javascript client-side scripting language (Brendan Eich, Netscape, 1995 ) C/Java-like syntax weakly typed, basic data types: double, string, array, object object-oriented, very dynamic unusual object model based on prototypes, not classes usage: <script> javascript code </script> <script src="url "></script> <sometag onsomeevent ='javascript code'> can catch events from mouse, keyboard,... can access browser's object interface window object for window itself document object (DOM == document object model) for entities on page can modify ("reflow") a page without completely redrawing it incompatibilities among browsers HTML, DOM, Javascript all potentially vary but it's getting much better: ECMA standard is being followed

Javascript constructs constants, variables, types operators and expressions statements, control flow functions arrays, objects libraries prototypes asynchrony, promises etc.

Constants, variables, operators constants doubles [no integer], true/false, null string, string, no difference between single and double quotes; interprets \ within either 16-bit Unicode characters variables hold strings or numbers, as in Awk, but not both simultaneously no automatic coercions; interpretation determined by operators and context var declaration (optional; just names the variable; always use it) variables are either global or local to a function only two scopes; block structure does not affect scope operators (changed in newer versions) mostly like C use === and!== for testing equality string concatenation uses + string[index] but no slices regular expressions in /.../

Unicode (www.unicode.org) universal character encoding scheme > 120,000 characters UTF-16: 16 bit internal representation encodes all characters used in all languages numeric value, name, case, directionality, expansion mechanism for > 2 16 characters UTF-8: byte-oriented external form variable-length encoding, self-synchronizing within a couple of bytes ASCII compatible: 7-bit characters occupy 1 byte 0bbbbbbb 110bbbbb 10bbbbbb 1110bbbb 10bbbbbb 10bbbbbb 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb Javascript supports Unicode char data type is 16-bit Unicode String data type is 16-bit Unicode chars \uhhhh is Unicode character hhhh (h == hex digit); use in "..." and '.'

Statements, control flow statements assignment, control flow, function call, braces for grouping semicolon terminator is optional (but always use it) // or /* */ comments control flow almost like C, etc. if-else, switch while, do-while, break, continue for ( ; ; ) for (var in array) try { } catch( ) { } finally { }

Functions functions are objects can store in variables, pass to functions, return from functions, etc. can be anonymous (no name) heavily used for callbacks function name(arg, arg, arg) { var... // local if declared with var; otherwise global statements } function sum(x, y) { return x + y; } var sum = function (x, y) { return x + y; } sum(1,2); standard libraries for math, strings, regular expressions, date/time,... browser DOM interface: dialog boxes, events,...

Closures A closure is a function that has access to its parent scope, even after the parent function has closed. (based on https://www.w3schools.com/js/js_function_closures.asp) var incr = (function () { var counter = 0; return function () { } })(); return counter += 1; incr(); incr(); incr(); console.log(incr());

Objects and arrays object: compound data type with any number of components very loosely, a cross between a structure and an associative array each property is a name-value pair accessible as obj.name or obj[ name ] values can be anything, including objects, arrays, functions, var point = {x:0, y:0, name: "origin"}; point.x = 1; point["y"] = 2; point.name = "not origin" array: an object with numbered values 0..len-1 elements can be any mixture of types var arr = [point, 1, "somewhere", {x:1, y:2}]; array operators: sort, reverse, join, push, pop, slice(start, end),

JSON : Javascript Object Notation (Douglas Crockford) lightweight data interchange format based on object literals simpler and clearer than XML, but without checking parsers and generators exist for most languages two basic structures object: unordered collection of name-value pairs (associative array) { string: value, string: value,... } array: ordered collection of values [ value, value,... ] string is "..." value is string, number, true, false, object or array Javascript eval function can convert this into a data structure: var obj = eval(json_string) // bad idea! potentially unsafe, since the string can contain executable code

Node.js: Javascript outside the browser

Formatter in Javascript var fs = require('fs'); var line = ''; var space = ''; var buf = fs.readfilesync(process.argv[2], 'utf-8'); buf = buf.replace(/\n/g, ' ').replace(/ +/, ' ').trim(); words = buf.split(/ +/); for (i = 0; i < words.length; i++) { addword(words[i]); } printline(); function addword(w) { if (line.length + w.length > 60) printline(); line = line + space + w; space = " "; } function printline() { if (line.length > 0) console.log(line); line = space = "" }