JavaScript. What s wrong with JavaScript?

Similar documents
CGS 3066: Spring 2015 JavaScript Reference

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: the Big Picture

CSC Web Programming. Introduction to JavaScript

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

JavaScript: The Good Parts

Chapter 3 - Simple JavaScript - Programming Basics. Lesson 1 - JavaScript: What is it and what does it look like?

JavaScript: Sort of a Big Deal,

Web Application Development

Client vs Server Scripting

JavaScript: The Basics

Manju Muralidharan Priya. CS4PM Web Aesthetics and Development WEEK 11

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

Javascript. UNIVERSITY OF MASSACHUSETTS AMHERST CMPSCI 120 Fall 2010

General Coding Standards

use attributes (); # optional, to get subroutine declarations = attributes::get(\&foo);

JavaScript CS 4640 Programming Languages for Web Applications

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

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

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

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

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

JScript Reference. Contents

Midterm Exam. 5. What is the character - (minus) used for in JavaScript? Give as many answers as you can.

Such JavaScript Very Wow

CS312: Programming Languages. Lecture 21: JavaScript

Web Programming/Scripting: JavaScript

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

(Refer Slide Time: 01:40)

CHAPTER 6 JAVASCRIPT PART 1

React. HTML code is made up of tags. In the example below, <head> is an opening tag and </head> is the matching closing tag.

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

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

JavaScript Syntax. Web Authoring and Design. Benjamin Kenwright

WebRTC: Possible? Don McGregor Research Associate MOVES Institute.

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

Task 1. Set up Coursework/Examination Weights

JavaScript CS 4640 Programming Languages for Web Applications

JavaScript Introduction

Lecture 8 (7.5?): Javascript

JavaScript Programming

2D Game design Intro to Html 5

Then there are methods ; each method describes an action that can be done to (or with) the object.

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

Functional JavaScript. Douglas Crockford Yahoo! Inc.

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

Object Model. Object Oriented Programming Spring 2015

HTML 5 and CSS 3, Illustrated Complete. Unit L: Programming Web Pages with JavaScript

Topics Covered Thus Far. CMSC 330: Organization of Programming Languages. Language Features Covered Thus Far. Programming Languages Revisited

CNIT 129S: Securing Web Applications. Ch 12: Attacking Users: Cross-Site Scripting (XSS) Part 2

CSE : Python Programming

JavaScript Introduction

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

CSE 341, Autumn 2015, Ruby Introduction Summary

dhtml2010.pdf February 25,

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

Introduction to Programming Using Java (98-388)

To implement binary trees, we have two prototypes: BTNode and BinaryTree.

CMSC 330: Organization of Programming Languages

Lesson 1: Writing Your First JavaScript

Client Side JavaScript and AJAX

JavaScript: More Syntax and Using Events

JavaScript Specialist v2.0 Exam 1D0-735

JAVASCRIPT. sarojpandey.com.np/iroz. JavaScript

Controlled Assessment Task. Question 1 - Describe how this HTML code produces the form displayed in the browser.

Module 5 JavaScript, AJAX, and jquery. Module 5. Module 5 Contains 2 components

Working with JavaScript

COMP519 Web Programming Lecture 27: PHP (Part 3) Handouts

Object Model Comparisons

CERTIFICATE IN WEB PROGRAMMING

COMS W3101: SCRIPTING LANGUAGES: JAVASCRIPT (FALL 2017)

COMP284 Scripting Languages Lecture 11: PHP (Part 3) Handouts

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

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

PHP by Pearson Education, Inc. All Rights Reserved.

Princess Nourah bint Abdulrahman University. Computer Sciences Department

JavaScript s role on the Web

write vs. writeln Prompting as Page Loads Today s Goals CSCI 2910 Client/Server-Side Programming Intermediate File vs. HTML Output

Ruby: Introduction, Basics

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End

Tutorial 10: Programming with JavaScript

JavaScript: Features, Trends, and Static Analysis

Notes on JavaScript (aka ECMAScript) and the DOM

ArcGIS API for JavaScript: Using Arcade with your Apps. Kristian Ekenes & David Bayer

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

PHP. Interactive Web Systems

CS 349 / SE 382 Scripting. Professor Michael Terry March 18, 2009

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

CS159. Nathan Sprague

CS1046 Lab 4. Timing: This lab should take you 85 to 130 minutes. Objectives: By the end of this lab you should be able to:

Lecture 8. ReactJS 1 / 24

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

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

Session 6. JavaScript Part 1. Reading

Test 1 Summer 2014 Multiple Choice. Write your answer to the LEFT of each problem. 5 points each 1. Preprocessor macros are associated with: A. C B.

Status Report. JSR-305: Annotations for Software Defect Detection. William Pugh Professor

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

CS 215 Software Design Homework 3 Due: February 28, 11:30 PM

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

Transcription:

JavaScript 1 What s wrong with JavaScript? A very powerful language, yet Often hated Browser inconsistencies Misunderstood Developers find it painful Lagging tool support Bad name for a language! Java in it is misleading In reality, it s a very elegant, powerful, objectoriented, and very expressive language 2

What it like? A little similarity with Java and C Quite some similarities with Perl Interpreted Support for regular expressions, handling arrays Object is more close to Perl associative array than Java s Untyped language 3 Case sensitive Coding in JavaScript Good practice to use ; to separate statements However, optional if each statement on separate line Watch out for line breaks, ; is inserted automatically! May cause headache at times, so better to use ; Same commenting style as C++/Java /**/ and // Try not to use HTML commenting convention 4

Types null and undefined are used to indicate null Strings are single quoted or double quoted with \ used for escape Strings are immutable A lots of things are objects For instance functions are objects as well This leads to pretty interesting behavior 5 Variables Variables are typeless Good practice to use the var declaration You may be able to omit it, but not a good idea Here is a catch. If you omit var, the variable is created global Any change made anywhere affects it! Variable scope: Global and local (function) No block level scope Variable defined any where in a function has function scope though not initialized until var is reached 6

Control Structure Most control structures are like C structure Statement Expressions if, switch, while, Exception handling much like Java try, catch, finally Two types of for loop C like for( ; ; ) { } for ([var] variable in object) { } Iterates over all properties of the object 7 Functions You may pass arguments Function may return a value function name(argumentname, ) { code return value; } Calling: var something = name(arg1, arg2); 8

Functions and Objects Functions are objects function foo(){ } is the same as Var foo = function(){ } This leads to some very powerful behavior you can assign handlers to objects for events, etc. 9 Objects Create an object with new var obj = new SomeThing(); Objects have properties and methods obj.someproperty = value; Var somevalue = obj.someproperty; obj.somemethod( ); You may also treat an object as associative array Obj[someProperty] = value; Var somevalue = obj[someproperty]; Date Object var now = Date(); // current date and time var newyearday = new Date(00, 0, 01); Month is 0 based! 10

How to create a class? Let s create the class used on previous page! function SomeThing() { this.someproperty = 0; } Notice how we assigned the property of the class But, then a class actually looks like a function Ugly Everything in a class is public 11 But, what about that method? somemethod was a method we called on that object of SomeThing Each class has a prototype member that holds its properties and methods You can access the prototype to add methods SomeThing.prototype.someMethod = function(val) { alert(val); } 12

How an object created? A object is created by copying the Prototype to proto property of an object An object passes unhandled calls to the proto Try this: for(var prop in obj) { print(prop); } someproperty somemethod for(var prop in obj. proto ) { print(prop); } somemethod 13 OK, but what about Inheritance? You can some what create inheritance function SomeThingMore () {} SomeThingMore.prototype = new SomeThing() var obj2 = new SomeThingMore() obj.somemethod(4) 14

But, two problems You must set prototype before adding any methods to sub class Also, you need to reset the constructor for the sub class 15 Client-side JavaScripting JavaScript is very useful to run on the frontend It allows you to validate data being sent to server It eliminates overhead by processing on browser side Which otherwise may have to be done on server Browser provides a context in which script runs Access to window object for execution context Client-side objects Event-driven model 16

Object Model Browser responsible for displaying HTML document in a window JavaScript has access to Document object that represents the HTML document Window object that represents the window that displays all global variables belong to this global object From the window object you may get to client side objects Frames, Document, Forms (within document), etc. Browser generates events upon user input you write and register event handler; browser notifies 17 JavaScript in HTML JavaScript needs to be provided for execution on browser May be provided in HTML document within <SCRIPT> and </SCRIPT> tags you may also mention external file using the SRC attribute of SCRIPT tag Example: <SCRIPT type= text/javascript > var today = new Date(); document.write( Today is + today.tolocalestring()); </SCRIPT> 18

Event Handling In the appropriate HTML tag, specify the event handler Write the event handler as a separate JavaScript function Example: <HTML> <FORM> <INPUT type="text" name="name" onchange="saysomething(this.value)" > </FORM> <SCRIPT> function saysomething(name) { alert(name + " you are good!"); } </SCRIPT> </HTML> 19