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

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

JavaScript CS 4640 Programming Languages for Web Applications

JavaScript CS 4640 Programming Languages for Web Applications

Client-Side Web Technologies. JavaScript Part I

CSC Web Programming. Introduction to JavaScript

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. History. Adding JavaScript to a page. CS144: Web Applications

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

JavaScript: The Basics

JavaScript I VP R 1. Copyright 2006 Haim Levkowitz. Outline

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

JavaScript: Introduction, Types

Such JavaScript Very Wow

Javascript. Many examples from Kyle Simpson: Scope and Closures

CHAPTER 6 JAVASCRIPT PART 1

Hands-On Perl Scripting and CGI Programming

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

Chapter 4 Basics of JavaScript

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

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

INF5750. Introduction to JavaScript and Node.js

CITS1231 Web Technologies. JavaScript Math, String, Array, Number, Debugging

CGS 3066: Spring 2015 JavaScript Reference

What Is JavaScript? A scripting language based on an object-orientated programming philosophy.

COMS W3101: SCRIPTING LANGUAGES: JAVASCRIPT (FALL 2017)

Introduction to Web Tech and Programming

JavaScript. What s wrong with JavaScript?

JavaScript Functions, Objects and Array

PERL Scripting - Course Contents

PES DEGREE COLLEGE BANGALORE SOUTH CAMPUS 1 K.M. before Electronic City, Bangalore WEB PROGRAMMING Solution Set II

5/19/2015. Objectives. JavaScript, Sixth Edition. Introduction to the World Wide Web (cont d.) Introduction to the World Wide Web

UNIT-4 JAVASCRIPT. Prequisite HTML/XHTML. Origins

4.1 Overview of JavaScript

Application Development in JAVA. Data Types, Variable, Comments & Operators. Part I: Core Java (J2SE) Getting Started

Shankersinh Vaghela Bapu Institue of Technology

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

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

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

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

CS312: Programming Languages. Lecture 21: JavaScript

Indian Institute of Technology Kharagpur. Javascript Part III. Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. I.I.T.

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

FALL 2017 CS 498RK JAVASCRIPT. Fashionable and Functional!

COMS 469: Interactive Media II

JavaScript: More Syntax and Using Events

Perl Scripting. Students Will Learn. Course Description. Duration: 4 Days. Price: $2295

JavaScript: the Big Picture

Web Site Development with HTML/JavaScrip

UNIT 3 SECTION 1 Answer the following questions Q.1: What is an editor? editor editor Q.2: What do you understand by a web browser?

JavaScript Introduction

GNU ccscript Scripting Guide IV

COMS 469: Interactive Media II

JAVA. Duration: 2 Months

E ECMAScript, 21 elements collection, HTML, 30 31, 31. Index 161

A Java Execution Simulator

IT6503 WEB PROGRAMMING. Unit-I

Web Programming/Scripting: JavaScript

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

Pace University. Fundamental Concepts of CS121 1

Produced by. App Development & Modelling. BSc in Applied Computing. Eamonn de Leastar

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

JavaScript II. Overview

Session 6. JavaScript Part 1. Reading

JavaScript: Introductionto Scripting

Govt. of Karnataka, Department of Technical Education Diploma in Computer Science & Engineering. Fifth Semester. Subject: Web Programming

CERTIFICATE IN WEB PROGRAMMING

JavaScript Basics. Mendel Rosenblum. CS142 Lecture Notes - JavaScript Basics

Tutorial 10: Programming with JavaScript

ADDING FUNCTIONS TO WEBSITE

Professional Course in Web Designing & Development 5-6 Months

JAVASCRIPT. Ajax Technology in Web Programming. Sergio Luján Mora. DLSI - Universidad de Alicante 1. Basic syntax and features

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

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

The JavaScript Language

By the end of this section of the practical, the students should be able to:

Client vs Server Scripting

INFS 2150 Introduction to Web Development and e-commerce Technology. Programming with JavaScript

Objectives. Introduction to JavaScript. Introduction to JavaScript INFS Peter Y. Wu, RMU 1

Chapter 6: Inheritance

Working with JavaScript

JavaScript Specialist v2.0 Exam 1D0-735

G Programming Languages - Fall 2012

Web Programming Step by Step


PHP Online Training. PHP Online TrainingCourse Duration - 45 Days. Call us: HTML

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

VTU Question Bank. UNIT 1 Introduction to WWW, XHTML

JAVASCRIPT. sarojpandey.com.np/iroz. JavaScript

CSI 3140 WWW Structures, Techniques and Standards. Browsers and the DOM

Ruby: Introduction, Basics

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

15.1 Origins and Uses of Ruby

Delivery Options: Attend face-to-face in the classroom or via remote-live attendance.

JAVASCRIPT - OBJECTS OVERVIEW

Session 16. JavaScript Part 1. Reading

Programming language components

Project 2: Scheme Interpreter

5. JavaScript Basics

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

Developing Ajax Web Apps with GWT. Session I

Transcription:

Basics of JavaScript History of the Web XHTML CSS Last Week Nan Niu (nn@cs.toronto.edu) CSC309 -- Fall 2008 2 Needs for Programming Capability XHTML and CSS allows the browser to passively display static content How to provide/request for more services? How to provide dynamic information? How to handle demands from the client? How to respond instantly to user actions? Demand for programming capability Browser as Development Platform Homogenous architecture Single client abstraction Easy to deploy and maintain Download on demand Efficient Fast download Most libraries are already cached on client 3 4 Origin of JavaScript Originally known as LiveScript by Netscape JScript by Microsoft Official name: ECMAScript www.ecma-international.org/publications/standards/ecma-262.htm Three parts Core Operators, expressions, statements, subprograms Client-side Server-side Complementary to Java Using Client-side JavaScript Embedded in XHTML documents Interpreted by the browser Objects representing windows, menus, pop-ups, dialog boxes, text areas, anchors, frames, history, cookies, and input/output Easy to implement event-driven computation Interaction with users Triggering computation on events Generate new content dynamically Transfer load from server to client Cannot replace all server-side computing 5 6 1

JavaScript Security Language/API limitations No file/directory access No raw network access; limited to either Load URLs Send HTML form data to Web servers, CGI scripts, e-mail addresses Same origin policy: can only read prop.s of doc.s and windows from the same host, port, protocol Privacy restrictions Cannot read history Cannot hide/show menubar, status line, scrollbars Cannot close a window not opened by itself Embedding in XHTML Directly <script type= text/javascript > </script> Indirectly <script type= text/javascript src= test.js /> Location <head> Definitions that are later called by elements in the document body <body> Process while parsing 7 8 Dynamic Typing Different than Java or C Variables can hold any type of value Number (8-byte IEEE fp) Boolean Function (first-class data type) Object Array (elements can be of mixed types) String and can hold values of different types at different times during execution Variables Declaration Explicit var i = 12; // no type declaration Implicit msg = Oilers ; Scope Global Declared outside functions Any variable implicitly defined Local Explicit declarations inside functions 9 10 var x=1; function f() { var y = 2; function g() { var z = 3; Scope Chain x: 1 y: 2 z: 3 global object call object of scope f() call object of scope g() Functions function function_name ([arg1], [argn]) { [return [value]]; Arguments Primitive types (string, number, boolean) are passed by value Object types are passed by reference 11 12 2

Control and Looping Control if switch Looping for while do while for in for (property in object) { for (element in array) { 13 Evaluation and Execution Evaluation As document is parsed, in order Execution Statement outside functions When it is encountered Statement inside function When function is called Event handler When event is triggered, e.g., <body onload= helloworld() > 14 Objects JavaScript is Object-Based rather than Object- Oriented No class construct No inheritance, polymorphism Objects are most like associative arrays var point = new Object(); point x = 2; point[ x ] = 2; //equivalent to previous point.print(); point[ print ](); //equivalent to previous Note: Object s definition is determined at run time Possible to dynamically add new properties or methods and to change the binding of methods at runtime Object Constructors function Rectangle_area() { return this.width * this.height; function Rectangle(w,h) { this.width = w; this.height = h; this.area = Rectangle_area; var rec = new Rectangle(2,4); rec.area(); rec[ area ](); Rec.newFunction = newpredeclaredfunc; 15 16 Alternatively function Rectangle(w,h) { this.width = w; this.height = h; this.area = function () { return this.width * this.height; ; var rec = new Rectangle(2,4); rec.area(); rec[ area ](); Rec.newFunction = newpredeclaredfunc; Predefined Objects Native/Built-in Number Boolean Primitive types are String automatically coerced Array into Objects Host navigator window document 17 18 3

Array Object var a = new Array(); // empty array var b = new Array( dog, 3, 8.4); var c = [2, 5, a, b ]; var d = new Array(10); // array of size 10 d[15] = hello ; // implicit extension Array Properties and Methods length join() reverse() sort() concat() slice() splice() push() / pop() shift() / unshift() tostring(). 19 20 navigator Object Represents the Browser appname Browser name appversion Browser version platfoms Client OS cookieenabled cpuclass Language mimetypes document Object Container for all HTML-related objects Content nested inside <html> tag open: opens output steam to document overwrites document write: appends text to document URL 21 22 Example 1: Customization Example 2: Factorial Content customization based on browser Print factorial table -- content overwriting 23 24 4

window Object Browser window itself open(url,name,[options]) open a new window close() alert() popup alert prompt() user input document widht, heigth toolbar, menubar, scrollbar, status, location rezisable screenx, screeny Example 3: Factorial version 2 Print factorial table on different window 25 26 Regular Expressions Compatible with Perl regular expression syntax \w Alphanumeric \d Numerical digit \s White spaces. Anything other than newline [abcde] Any of a,b,c,d,e [a-e] Same as above [^a-e] Anything but a to e exp?,exp+,exp*0 or 1, 1 or more, 0 or more exp{x,y At least x but less than y expa expb expa or expb 27 Regular Expressions RegExp object var animalsearch = /bear/ var animalsearch = new RegExp( bear ) exec(str) search patter and return result test(str) returns true if match If (animalsearch.test( The little bear )) { Alert( I found a bear ); 28 Strings and Regular Expressions match(regexpobj) Verify input var phone = "416-4403467"; if (phone.match(/\d{3-\d{7/)) return true; replace(regexpobj, str) Replace part of a string var str = "One elephant and two zebras"; var matches = str.replace(/two/,"three"); Example 4: Form Validation 29 30 5