J AVA S CRIPT Shadi Banitaan 1. O UTLINE Introduction JavaScript Functions Using Objects in JavaScript Built-in Objects User-Defined Objects Examples.

Slides:



Advertisements
Similar presentations
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Advertisements

Java Script Session1 INTRODUCTION.
1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
The Web Warrior Guide to Web Design Technologies
Advanced JS The World's Most Misunderstood Programming Language ) Douglas Crockford( Shimon Dahan
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Introduction to Scripting.
Road Map Introduction to object oriented programming. Classes
CS 898N – Advanced World Wide Web Technologies Lecture 14: JavaScript Chin-Chih Chang
ASP.NET Programming with C# and SQL Server First Edition
Lesson15. JavaScript Objects Objects encapsulate data (properties) and behavior(methods); the properties and the methods of an object are tied together.
JavaScript Demo Presented by … Jaisingh Sumit jain Sudhindra Taran Deep arora.
The PHP Story. PHP Story PHP is a programming language. Incorporate(join) sophisticated business logic. Widely used general purpose scripting language.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
4.1 JavaScript Introduction
JavaScript: Control Structures September 27, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel,
Programming Languages and Paradigms Object-Oriented Programming.
Server vs Client-side validation. JavaScript JavaScript is an object-based language. JavaScript is based on manipulating objects by modifying an object’s.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
More about JavaScript INE2720 Web Application Software Development Essential Materials.
Introduction to JavaScript 11 Introduction to Programming the WWW I CMSC Winter 2004 Lecture 14.
Lectured By: Vivek Dimri Asst. Professor, SET, Sharda University
Database-Driven Web Sites, Second Edition1 Chapter 3 INTRODUCTION TO CLIENT-SIDE SCRIPTS.
1 CLIENT-SIDE SCRIPTS. Objectives 2 Learn how to reference objects in HTML documents using the HTML DOM and dot syntax Learn how to create client-side.
Chapter 3 : Processing on the Front End JavaScript Technically its name is ECMA-262, which refers to the international standard which defines it. The standard.
1 JavaScript. 2 What’s wrong with JavaScript? A very powerful language, yet –Often hated –Browser inconsistencies –Misunderstood –Developers find it painful.
JavaScript Introduction
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
Javascript. Outline Introduction Fundamental of JavaScript Javascript events management DOM and Dynamic HTML (DHTML)
SE-2840 Dr. Mark L. Hornick 1 Modifying webpage behavior using client-side scripting Javascript.
JavaScript, Fourth Edition
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Using Client-Side Scripts to Enhance Web Applications 1.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
DHTML AND JAVASCRIPT Genetic Computer School LESSON 5 INTRODUCTION JAVASCRIPT G H E F.
20-753: Fundamentals of Web Programming 1 Lecture 12: Javascript I Fundamentals of Web Programming Lecture 12: Introduction to Javascript.
JavaScript Introduction 1. What is Java Script ? JavaScript is a client-side scripting language. A scripting language is a lightweight programming language.
JS Basics 1 Lecture JavaScript - Basics. JS Basics 2 What is JavaScript JavaScript is a “simple”, interpreted, programming language with elementary object-
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
JavaScript Syntax, how to use it in a HTML document
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
Introduction to JavaScript CS101 Introduction to Computing.
Overview of Form and Javascript fundamentals. Brief matching exercise 1. This is the software that allows a user to access and view HTML documents 2.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Objects and Classes.
JavaScript Overview Developer Essentials How to Code Language Constructs The DOM concept- API, (use W3C model) Objects –properties Methods Events Applications;
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
Web Programming Overview. Introduction HTML is limited - it cannot manipulate data How Web pages are extended (include): –Java: an object-oriented programming.
Java Script. introduction Today’s web sites need to go much beyond HTML. browsing through a web site, to actually interact with the web site. The web.
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
CGS 3066: Web Programming and Design Spring 2016 Introduction to JavaScript.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
JavaScript: A short introduction Joseph Lee Created by Joseph Lee.
Introduction to JavaScript MIS 3502, Fall 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 9/29/2016.
“Under the hood”: Angry Birds Maze
Chapter 4 Client-Side Programming: the JavaScript Language
JavaScript is a programming language designed for Web pages.
Barb Ericson Georgia Institute of Technology May 2006
Scope, Objects, Strings, Numbers
JavaScript.
PHP.
“Under the hood”: Angry Birds Maze
JavaScript CS 4640 Programming Languages for Web Applications
Tutorial 10: Programming with javascript
JavaScript Basics What is JavaScript?
Introduction to JavaScript
JavaScript CS 4640 Programming Languages for Web Applications
Presentation transcript:

J AVA S CRIPT Shadi Banitaan 1

O UTLINE Introduction JavaScript Functions Using Objects in JavaScript Built-in Objects User-Defined Objects Examples Events 2

J AVA VS J AVA S CRIPT 3 JavaScriptJava Interpreted (not compiled) by client.Compiled on server before execution on client. Object-based. Code uses built-in, extensible objects, but no classes Object-oriented. Applets consist of object classes Code integrated with, and embedded in, HTML. Applets distinct from HTML (accessed from HTML pages). Variable data types not declared (loose typing). Variable data types must be declared (strong typing).

W EB S CRIPTING L ANGUAGES Fewer features Can be client side or Server side Server side Invoked from browser Run on the server Client side - JavaScript Invoked and Run on the browser 4

A DDING I NTEGERS 5

6

J AVA S CRIPT : F UNCTIONS A function is a block of organized reusable code (a set of statements) for performing a single or related action. Begins with keyword “ function ” and the function name and “ ( … ) ” Inside the parentheses We can pass parameters to the function E.g. function myfunction(arg1, arg2) { … } Built-in and user-defined functions 7

B UILT -I N F UNCTIONS Functions provided by the language and you cannot change them to suit your needs. Some of the built-in functions in JavaScript are shown here: isFinite: Determines if a number is finite isNaN: Determines whether a value is “Not a Number” 8

U SER -D EFINED F UNCTIONS 9

J AVA S CRIPT : O BJECTS You can instantiate an object by using the constructor function JavaScript is said to be an Object-based programming language What is property? A variable belongs to the object. What is method? It is a function belongs to the object 10

J AVA S CRIPT : O BJECTS Built-in Objects: Math, Array, and String. E.g.) Math.random() User-Defined Objects: The Class: JavaScript uses functions as classes. E.g.) function Person() { } The Object (Class Instance) var person1 = new Person(); var person2 = new Person(); The Property (object attribute): Properties are variables contained in the class 11

M ATH O BJECT 12

M ATH O BJECT 13

S TRING O BJECT 14

S TRING O BJECT 15

D ATE O BJECT 16

D ATE O BJECT 17

D ATE O BJECT 18

DOCUMENT O BJECT Each HTML document loaded into a browser window becomes a Document object. Provided by the browser and allows JavaScript code to manipulate the current document in the browser 19

DOCUMENT O BJECT 20

DOCUMENT O BJECT 21

E XTRACTING DOCUMENT INFORMATION 22

E XTRACTING DOCUMENT INFORMATION 23

B OOLEAN O BJECT The Boolean object is used to convert a non- Boolean value to a Boolean value (true or false). 24

N UMBER O BJECT The Number object is an object wrapper for primitive numeric values. 25

J AVA S CRIPT : USER - DEFINED OBJECTS Fields Can Be Added On-the-Fly Adding a new property (field) is a simple matter of assigning a value to one If the field doesn’t already exist when you try to assign to it, JavaScript will create it automatically. For instance: var test = new Object(); test.field1 = "Value 1"; // Create field1 property test.field2 = 7; // Create field2 property 26

L ITERAL N OTATION We can create objects using a shorthand “literal” notation of the form { field1:val1, field2:val2,..., fieldN:valN } For example, the following gives equivalent values to object1 and object2 var object1 = new Object(); object1.x = 3; object1.y = 4; object1.z = 5; object2 = { x:3, y:4, z:5 }; 27

O BJECTS : I TERATES O VER P ROPERTIES JavaScript, unlike Java or C++, has a construct that lets you easily retrieve all of the fields of an object The basic format is as follows: For (fieldName in object) { doSomethingWith(fieldName); } Also, given a field name, you can access the field via object["field"] as well as via object.field 28

O BJECTS : I TERATES O VER P ROPERTIES 29

O BJECTS : I TERATES O VER P ROPERTIES 30

O BJECTS : C ONSTRUCTOR A “Constructor” is Just a Function that Assigns to “this” JavaScript does not have an exact equivalent to Java’s class definition The closest you get is when you define a function that assigns values to properties in the this reference function Ship(x, y, speed, direction) { this.x = x; this.y = y; this.speed = speed; this.direction = direction; } 31

E XAMPLE (C ONSTRUCTOR ) 32

E XAMPLE (P ROTOTYPE ) 33

E XAMPLE (U SER - DEFINED O BJECT ) 34

E XAMPLE (U SER - DEFINED O BJECT ) 35

E XAMPLE (I NSTANCE ) 36

N ESTED O BJECT 37

E VENTS JavaScript events allow scripts to respond to user interactions and modify the page accordingly Events and event handling help make web applications more dynamic and interactive

S IMPLE BUTTON 39

M OUSE E VENTS 40