1 JavaScript. 2 What’s wrong with JavaScript? A very powerful language, yet –Often hated –Browser inconsistencies –Misunderstood –Developers find it painful.

Slides:



Advertisements
Similar presentations
Chapter 7 JavaScript: Introduction to Scripting. Outline Simple Programs Objects and Variables Obtaining User Input with prompt Dialogs – –Dynamic Welcome.
Advertisements

JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Java Script Session1 INTRODUCTION.
Javascript It’s not JAVA. What do these all have in common?
The Web Warrior Guide to Web Design Technologies
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Introduction to Scripting.
12-Jun-15 JavaScript Language Fundamentals I. 2 About JavaScript JavaScript is not Java, or even related to Java The original name for JavaScript was.
Javascript Client-side scripting. Up to now  We've seen a little about how to control  content with HTML  presentation with CSS  Javascript is a language.
Tutorial 10 Programming with JavaScript
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
Javascript and the Web Whys and Hows of Javascript.
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,
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
SYST Web Technologies SYST Web Technologies Lesson 6 – Intro to JavaScript.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
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.
CISC474 - JavaScript 03/02/2011. Some Background… Great JavaScript Guides: –
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
SE-2840 Dr. Mark L. Hornick 1 Modifying webpage behavior using client-side scripting Javascript.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
Tutorial 10 Programming with JavaScript. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
Done by: Hanadi Muhsen1 Tutorial 1.  Learn the history of JavaScript  Create a script element  Write text to a Web page with JavaScript  Understand.
Using Client-Side Scripts to Enhance Web Applications 1.
20-753: Fundamentals of Web Programming 1 Lecture 12: Javascript I Fundamentals of Web Programming Lecture 12: Introduction to Javascript.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
Introduction.  The scripting language most often used for client-side web development.  Influenced by many programming languages, easier for nonprogrammers.
Window Control with JavaScript Chapter 5 JavaScript for the WWW.
Javascript. What is JavaScript? Scripting (interpreted) language designed for the web Beware: JavaScript is case sensitive.
1 JavaScript
JavaScript Syntax, how to use it in a HTML document
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
JavaScript Introduction.  JavaScript is a scripting language  A scripting language is a lightweight programming language  A JavaScript can be inserted.
Web111a_chapt08.ppt HTML: Section 8 JavaScript CGI Programs (Server Side programs) Common Gateway Interface Run on server Communicate with user across.
Introduction To JavaScript. Putting it Together (page 11) All javascript must go in-between the script tags. All javascript must go in-between the script.
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
CSD 340 (Blum)1 Starting JavaScript Homage to the Homage to the Square.
Introduction into JavaScript Java 1 JavaScript JavaScript programs run from within an HTML document The statements that make up a program in an HTML.
COP 3813 Intro to Internet Computing Prof. Roy Levow Lecture 4 JavaScript.
Java Script About Java Script Document Object Model Incorporating JavaScript Adding JavaScript to HTML Embedding a Javascript External Scripts Javascript.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
JavaScript and AJAX 2nd Edition Tutorial 1 Programming with JavaScript.
Introduction to JavaScript MIS 3502, Fall 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 9/29/2016.
Module 1 Introduction to JavaScript
Donna J. Kain, Clarkson University
Scope, Objects, Strings, Numbers
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
Introduction to JavaScript
JavaScript an introduction.
A second look at JavaScript
CS5220 Advanced Topics in Web Programming JavaScript Basics
Tutorial 10 Programming with JavaScript
Introduction to JavaScript
JavaScript CS 4640 Programming Languages for Web Applications
Tutorial 10: Programming with javascript
JavaScript CS 4640 Programming Languages for Web Applications
Presentation transcript:

1 JavaScript

2 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, object- oriented, and very expressive language

3 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

4 Coding in JavaScript Case sensitive 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

5 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

6 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

7 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

8 Functions You may pass arguments Function may return a value function name(argumentName, …) { … code return value; } Calling: var someThing = name(arg1, arg2);

9 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.

10 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 !

11 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

12 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); }

13 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

14 OK, but what about Inheritance? You can some what “create” inheritance function SomeThingMore () {} SomeThingMore.prototype = new SomeThing() var obj2 = new SomeThingMore() obj.someMethod(4)

15 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

16 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

17 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

18 JavaScript in HTML JavaScript needs to be provided for execution on browser May be provided in HTML document within and tags –you may also mention external file using the SRC attribute of SCRIPT tag Example: var today = new Date(); document.write(“Today is “ + today.toLocaleString());

19 Event Handling In the appropriate HTML tag, specify the event handler Write the event handler as a separate JavaScript function Example: function saySomeThing(name) { alert(name + " you are good!"); }