Princeton University COS 333: Advanced Programming Techniques A Subset of JavaScript

Similar documents
Princeton University COS 333: Advanced Programming Techniques A Subset of JavaScript

JAVASCRIPT BASICS. Handling Events In JavaScript. In programing, event-driven programming could be a programming

LECTURE-3. Exceptions JS Events. CS3101: Programming Languages: Javascript Ramana Isukapalli

LECTURE-2. Functions review HTML Forms. Arrays Exceptions Events. CS3101: Scripting Languages: Javascript Ramana Isukapalli

JavaScript Programming Chris Seddon

Fundamentals of Website Development

Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England and Associated Companies throughout the world

HTML User Interface Controls. Interactive HTML user interfaces. Document Object Model (DOM)

New Perspectives on Creating Web Pages with HTML. Tutorial Objectives

Client-Side Web Technologies. JavaScript Part I

710 Index Attributes, 127 action attribute, 263 assigning, bottom attribute, domain name attribute, 481 expiration date attribute, 480 8

CISH-6510 Web Application Design and Development. Overview of JavaScript. Overview

JavaScript Handling Events Page 1

Princeton University COS 333: Advanced Programming Techniques A Subset of PHP

Events: another simple example

Key features. Nothing to do with java It is the Client-side scripting language Designed to add interactivity to HTML pages

CSC Web Programming. Introduction to JavaScript

Such JavaScript Very Wow

Full file at Tutorial 2: Working with Operators and Expressions

Want to add cool effects like rollovers and pop-up windows?

Beijing , China. Keywords: Web system, XSS vulnerability, Filtering mechanisms, Vulnerability scanning.

CSS The web browser uses its own resources, and eases the burden on the server. It has fewer features than server side scripting.

Chapter 14 - Dynamic HTML: Event Model

TEXTAREA NN 2 IE 3 DOM 1

Canvas & Brush Reference. Source: stock.xchng, Maarten Uilenbroek

Introduction to Programming Using Java (98-388)

CSC Javascript

Introduction to DHTML

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 for PHP Developers

Coding in JavaScript functions

Window Interface. get only ApplicationCache window.applicationcache. get only boolean window.closed

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

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

Installation and Configuration Manual

Variables and Typing

This tutorial has been designed for beginners in HTML5 to make them understand the basicto-advanced

1$ 5 ! $ 6 4 * Source: 0 "!*! 0! * 8 97 ?!$ 5 0 *! 4! $ 0 : * ' () 7;7 7<7

JSF - H:INPUTSECRET. Class name of a validator that s created and attached to a component

Outline. Lecture 4: Document Object Model (DOM) What is DOM Traversal and Modification Events and Event Handling

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

The administrator can configure and manage system environment for Knox Manage for efficient operation.

link document.getelementbyid("coffee").style.borderwidth = "0px" document.getelementbyid("tea").style.borderwidth = "10px"

UNIT - III. Every element in a document tree refers to a Node object. Some nodes of the tree are

JAVASCRIPT FOR PROGRAMMERS

CGS 3066: Spring 2015 JavaScript Reference

JavaScript. The Basics

Introduction to JavaScript, Part 2

DOM Primer Part 2. Contents

JavaScript and XHTML. Prof. D. Krupesha, PESIT, Bangalore

Working with JavaScript

JavaScript Introduction

JScript Reference. Contents

Lecture 14. Introduction to JavaScript. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

Client vs Server Scripting

Note: Java and JavaScript are two completely different languages in both concept and design!

Language Fundamentals Summary

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

Program Design Phase. Algorithm Design - Mathematical. Algorithm Design - Sequence. Verify Algorithm Y = MX + B

INTRODUCTION TO WEB DEVELOPMENT AND HTML. Lecture 15: JavaScript loops, Objects, Events - Spring 2011

DC71 INTERNET APPLICATIONS JUNE 2013

CHAPTER 5: JavaScript Basics 99

Session 6. JavaScript Part 1. Reading

JavaScript CS 4640 Programming Languages for Web Applications

Client-Side Web Programming. Copyright 2017 by Robert M. Dondero, Ph.D. Princeton University

JavaScript CS 4640 Programming Languages for Web Applications

CS312: Programming Languages. Lecture 21: JavaScript

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

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

Javascript. A key was pressed OR released. A key was released. A mouse button was pressed.

JSF - H:SELECTONEMENU

c122mar413.notebook March 06, 2013

Type Conversion. and. Statements

COMP519 Web Programming Lecture 11: JavaScript (Part 2) Handouts

Place User-Defined Functions in the HEAD Section

Phụ lục A. Sơ đồ các đối tượng trong trình duyệt

COMP519 Web Programming Lecture 16: JavaScript (Part 7) Handouts

Photo from DOM

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

HTML5 and CSS3 More JavaScript Page 1

JavaScript: Fundamentals, Concepts, Object Model

Princeton University COS 333: Advanced Programming Techniques A Subset of C90

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

Digitizing Sound and Images III Storing Bits

HTML5-CanIuse 1 HTML5-Tags Ordered Alphabetically 6 HTML5-Element Reference 12 HTML5-Attribute Reference 19 HTML5-Global Attributes 33 HTML5-Event

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

Princeton University COS 333: Advanced Programming Techniques A Subset of Python 2.7

Web Programming and Design. MPT Junior Cycle Tutor: Tamara Demonstrators: Aaron, Marion, Hugh

Continues the Technical Activities Originated in the WAP Forum

Object Overview. Built-in Objects -- String (cont d) Built-in Objects -- String &6&7XWRULDO -DYD6UFLSW (GZDUG;LD )HEUXDU\ Built-in objects

CSC Java Programming, Fall Java Data Types and Control Constructs

AJAX Securely by Matt Payne, CISSP

The first sample. What is JavaScript?

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

3Lesson 3: Functions, Methods and Events in JavaScript Objectives

About the Author. Liability

Principles of Programming Languages

Dynamic Web Pages - Integrating JavaScript into a SAS Web Application Caroline Bahler, ASG, Inc.

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. VBScript

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

Transcription:

Princeton University COS 333: Advanced Programming Techniques A Subset of JavaScript Program Structure <body> <script> function sqr(i) var result; // Otherwise result would be global. result = i * i; // Semicolons usually optional. return result; document.write(sqr(5)); </script> </body> ----------------------------------------------------------------------------------- <head> <script> function sqr(i) var result; // Otherwise result would be global. result = i * i; // Semicolons usually optional. return result; </script> </head> <body onload="document.write(sqr(5)); "> </body> ----------------------------------------------------------------------------------- <script src="http://someserver/somescript.js"></script> Building and Running Handled by browser. Page 1 of 5

Reserved Words (ECMAScript6) break, case, catch, class, const, continue, debugger, default, delete, do, else, export, extends, finally, for, function, if, import, in, instanceof, new, return, super, switch, this, throw, try, typeof, var, void, while, with, yield Primitive Data Types Integer: 1, 12345, 01, 012345, 0x1, 0x1DB5 Floating point: 0.0, 1.23, 1.23e4 String: 'hi', "hi" Boolean: true, false Null object: null Explicit type conversions Integer: Floating point: Boolean: String: parseint(floatorstring) parsefloat(intorstring) Boolean(intOrFloatOrString) String(intOrFloatOrBoolean) Implicit type conversions n = '123'; n *= 1; // Convert n to a number n = 123; n += ''; // Convert n to a string Operators Arithmetic: +, -, *, /, %, ++,, unary -, unary + Assignment: =, *=, /=, %=, +=, -=, <<=, >>=, >>>=, &=, ^=, = Bitwise: &,, ^, ~, <<, >>, >>> Comparison: ==,!=, ===,!==, >, >=, <, <=, Logical: &&,,! String: +, += Member: object.property, object["property"] Conditional: (condition? IfTrue : iffalse) Sequence:, Others: delete, function, get, in, instanceof, let, new, set, this, typeof, void, yield Statements Var var variable; Declares variable to be local to a function; otherwise it would be global Compound statement statement Selection if (expr) Page 2 of 5

else switch (expr) case value1: statements; break; case value2: statements; break; default: statements; Note: false == 0 == null == '' == ""; true == anything else Iteration while (expr) do while expr; break as in C for (initialexpr; expr; finalexpr) for (key in associativearray) Note: false == 0 == null == '' == ""; true == anything else continue as in C Exception Handling try statements; catch (exception) document.write(exception.message); throw 'someexception'; Function Definition function f(a, b, c) statements; function f() for (i = 0; i < arguments.length; i++) arguments[i] return as in C Page 3 of 5

Function Call f(expr, ); Object references are passed by value Data Structures Arrays colors1 = ['red', 'green', 'blue']; colors2 = Array('orange', 'maroon', 'aqua'); for (var i = 0; i < colors2.length; i++) document.write(colors2[i]); Associative Arrays yanks = 'Ruth': 'RF', 'Gehrig': '1B', 'Mantle': 'CF', 'Jeter': 'SS'; for (var yank in yanks) document.write(yank + ' = ' + yanks[yank]); Objects An object is an associative array Each object created via MyClass has its own copy of each function: function MyClass(i) this.i = i this.get = function() return this.i; this.set = function(i) this.i = i; obj1 = new MyClass(5); i = obj1.get(); obj2.set(6); All objects created via AnotherClass share copies of a single set of functions: function AnotherClass(i) this.i = i; AnotherClass.prototype.get = function() return this.i; AnotherClass.prototype.set = function(i) this.i = i; obj2 = new AnotherClass(5) ; i = obj2.get(); obj2.set(6); Standard Built-In Objects Value properties: Return a simple value Infinity, NaN, undefined, null literal Function properties: Functions that are called globally rather than on an object eval(), uneval(), isfinite(), isnan(), parsefloat(), parseint(), decodeuri(), Page 4 of 5

decodeuricomponent(), encodeuri(), encodeuricomponent() Fundamental objects: Basic objects upon which all other objects are based Object, Function, Boolean, Symbol, Error, EvalError, InternalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError Numbers and dates: Objects that represent numbers, dates, and mathematical calculations Number, Math, Date Text processing: Objects that represent strings and support manipulating them And others String, RegExp DOM Objects window object Represents the browser window. Contains a reference to a document object. Event handlers: onabort, onbeforeunload, onblur, onchange, onclick, onclose, oncontextmenu, ondragdrop, onerror, onfocus, onhashchange, onkeydown, onkeypress, onkeyup, onload, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, onmosbeforepaint, onpaint, onpopstate, onreset, onresize, onscroll, onselect, onsubmit, onunload, onpageshow, onpagehide document object Represents the current document. Contains references to element objects. Event handlers: ononline, onoffline, onreadystatechange element objects Each represents an HTML element. Each contains references to attributes and children elements. Event handlers: onafterscriptexecute, onbeforescriptexecute, oncopy, oncut, onpaste, onbeforeunload, onblur, onchange, onclick, oncontextmenu, ondblclick, onfocus, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, onresize, onscroll Debugging In Firefox: Tools Web Developer Browser Console In Chrome: More tools Developer Tools Etc. We'll cover other features of JavaScript throughout the course as necessary. Copyright 2017 by Robert M. Dondero, Jr. Page 5 of 5