Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Introduction to ASP.NET.
Advertisements

JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
The Web Warrior Guide to Web Design Technologies
Advanced JS The World's Most Misunderstood Programming Language ) Douglas Crockford( Shimon Dahan
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
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
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
Chapter 6 DOJO TOOLKITS. Objectives Discuss XML DOM Discuss JSON Discuss Ajax Response in XML, HTML, JSON, and Other Data Type.
Course Textbook: Build Your Own ASP.Net Website: Chapter 2
Taking JavaScript Seriously IS NOT THE WORST IDEA.
OOP Languages: Java vs C++
UNIVERSIDAD TECNOLÓGICA ECOTEC. ISO 9001:2008 Module 2 Creating Web Applications by Using Microsoft® Visual Studio 2010 and Microsoft.NET–Based Languages.
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.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
J AVA S CRIPT Shadi Banitaan 1. O UTLINE Introduction JavaScript Functions Using Objects in JavaScript Built-in Objects User-Defined Objects Examples.
The Document Object Model. Goals Understand how a JavaScript can communicate with the web page in which it “lives.” Understand how to use dot notation.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
Database-Driven Web Sites, Second Edition1 Chapter 3 INTRODUCTION TO CLIENT-SIDE SCRIPTS.
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.
Tutorial 2 Variables and Objects. Working with Variables and Objects Variables (or identifiers) –Values stored in computer memory locations –Value can.
SE-2840 Dr. Mark L. Hornick 1 Modifying webpage behavior using client-side scripting Javascript.
JavaScript, Fourth Edition
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Introduction to JavaScript Gordon Tian
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.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
Tutorial 10 Programming with JavaScript. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
Tutorial 10 Programming with JavaScript
CNIT 133 Interactive Web Pags – JavaScript and AJAX Advanced topic - variable.
Object Oriented JavaScript. JavaScript Really only 4 types in JavaScript – number, string, boolean – Object (includes arrays) Remember that an object.
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
JavaScript Justin Skinner Programming Languages. JavaScript JavaScript is not Java nor a subset But JavaScript does share the C-family syntax with Java.
4.4 JavaScript (JS) Deitel Ch. 7, 8, 9, JavaScript & Java: Similarities JS (JavaScript) is case-sensitive Operators –arithmetic: unary +, unary.
Javascript. What is JavaScript? Scripting (interpreted) language designed for the web Beware: JavaScript is case sensitive.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
CSE 341 Lecture 29 a JavaScript, the bad parts slides created by Marty Stepp see also: JavaScript: The Good Parts, by.
JavaScript Syntax, how to use it in a HTML document
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
Prototypal Inheritance. Can We Do Inheritance Without Classes? How do we share behaviour across objects.
JavaScript, Fourth Edition
Julian on JavaScript: Functions Julian M Bucknall, CTO.
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
COP 3813 Intro to Internet Computing Prof. Roy Levow Lecture 4 JavaScript.
“The world’s most misunderstood language has become the world’s most popular programming language” Akshay Arora
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
MIT-AITI: Functions Defining and Invoking Functions Functions as Data Function Scope: The call Object Function Arguments: The arguments objects Function.
PHP Reusing Code and Writing Functions 1. Function = a self-contained module of code that: Declares a calling interface – prototype! Performs some task.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Object Oriented JavaScript. JavaScript Really only 4 types in JavaScript – number, string, boolean – Object (includes arrays) Remember that an object.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
JavaScript, Sixth Edition
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
JavaScript and AJAX 2nd Edition Tutorial 1 Programming with JavaScript.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
JavaScript Programming. What Is JavaScript “the most popular programming language in the world”— w3schools.com “the language for HTML, the Web, computers,
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
Javascript Prof. Wenwen Li School of Geographical Sciences and Urban Planning 5644 Coor Hall
Chapter 4 Client-Side Programming: the JavaScript Language
Scope, Objects, Strings, Numbers
CS5220 Advanced Topics in Web Programming JavaScript Basics
CS3220 Web and Internet Programming JavaScript Basics
CS3220 Web and Internet Programming JavaScript Basics
Introduction to JavaScript
Presentation transcript:

Rich Internet Applications 2. Core JavaScript

The importance of JavaScript Many choices open to the developer for server-side Can choose server technology for development and deployment ASP.NET, PHP, Ruby on Rails, etc No choice for development of native browser application Must work with the user’s browser The only programming language which is universally supported is JavaScript Rich Internet Applications2. Core JavaScript #2

Why learn JavaScript? No just browser apps – there is strong interest in JavaScript for server applications (node.js) and desktop apps (Windows 8 Metro, with HTML 5) Libraries such as jQuery are very popular Can aid development by simplifying syntax and abstracting browser differences However, important to understand the underlying language, which has features which can seem “alien” to C# developers Rich Internet Applications2. Core JavaScript #3

Resources Reading JavaScript: The Definitive Guide (6 th Edition), David Flanagan (very thorough!) JavaScript: The Good Parts, Douglas Crockford W3Schools Useful development tools include: Text editor, or Visual Studio Firefox with Firebug for debugging jsFiddle for quick experimenting and sharing Rich Internet Applications2. Core JavaScript #4

Similarities to C# Operators + expressions Statements; Code blocks {} if statements for and while loops switch statements try-catch … Rich Internet Applications2. Core JavaScript #5

Types and values Values can be of primitive and object types Primitive – strings, numbers, boolean, special types (null, undefined) Any value that is not one of these is an object Rich Internet Applications2. Core JavaScript #6

Variables Declare with var key word No type specified - dynamic typing Not the same as var (or dynamic) in C# Scope is code block in which declared Can have global variables – if not declared, scope is automatically global Rich Internet Applications2. Core JavaScript #7

Objects (reference types) Object is collection of name/value pairs Value can itself be an object – can have complex object structures Can create with object literal expressions (similar to JSON) Rich Internet Applications2. Core JavaScript #8

Arrays Numerically indexed lists of values Rich Internet Applications2. Core JavaScript #9

Arrays and objects Arrays can contain objects Objects can have array properties Rich Internet Applications2. Core JavaScript #10

For-in loop Iterates through the properties of an object Loop variable is the name of the property If object is an array, the loop variable is the index Can access value using property name or index Rich Internet Applications2. Core JavaScript #11

Functions Functions are parameterised blocks of code which can be invoked over and over again Functions are values which can be assigned to variables Can be passed as parameters to other functions Often used to define callback functions Similar to delegates in C# Can be nested Rich Internet Applications2. Core JavaScript #12

Functions Rich Internet Applications2. Core JavaScript #13

Methods Functions can be assigned to the properties of an object These functions are methods of the object Can be added dynamically Rich Internet Applications2. Core JavaScript #14

Global object When the JavaScript interpreter starts (or when page loads), it creates a new global object and gives it an initial set of properties : global properties like undefined, Infinity, and NaN global functions like isNaN(), parseInt() and eval() constructor functions like Date(), RegExp(), String(), Object(), and Array() global objects like Math and JSON In the browser there is also a Window object which defines other globals Rich Internet Applications2. Core JavaScript #15

Classes Classes are important when we use patterns and frameworks which provide structure in JavaScript applications, e.g. MVC Need classes for “model” JavaScript is object-oriented, but the syntax for creating “classes” is very different from languages like C# and Java Prototype-based programming Similar languages include ActionScript, Lua Rich Internet Applications2. Core JavaScript #16

Classes JavaScript does not have class definitions Instead of class definition, we can use: Constructor function, which defines properties Prototype object associated with the constructor function, which defines methods Instances are created with the new keyword Instances inherit methods from prototype Rich Internet Applications2. Core JavaScript #17

Class example Rich Internet Applications2. Core JavaScript #18

Constructors and prototypes This works through the existence of two properties of JavaScript objects constructor a reference to the function that created the instance's prototype prototype An object from which other objects can inherit properties Instances inherit properties from their constructor function’s prototype Rich Internet Applications2. Core JavaScript #19

Constructors and prototypes Rich Internet Applications2. Core JavaScript #20

Accessing constructor and prototype Access constructor through instance or constructor prototype Can’t directly access prototype through instance, but can use non-standard __proto__ property in some browsers Rich Internet Applications2. Core JavaScript #21

Prototype chain When retrieving a property, JavaScript first looks to see if the property is defined directly in the object If not, it then looks at the object's prototype to see if the property is defined there This continues up the prototype chain until reaching the root prototype, Object.prototype Object is the prototype for Point in our example Rich Internet Applications2. Core JavaScript #22

Prototype chain Rich Internet Applications2. Core JavaScript #23

Prototype chain example One method defined in object, one in prototype Rich Internet Applications2. Core JavaScript #24

Changing the prototype Prototype is dynamic, like any other JavaScript property Can add new properties to a prototype, and existing and new instances will inherit these Can replace prototype with a new object – existing instances retain link to their original prototype Can replace instance prototype through __proto__ Rich Internet Applications2. Core JavaScript #25

Subclasses Create a subclass by attaching a new constructor function to a prototype chain New class inherits prototype properties Can override and extend through properties in new prototype Can pass parameters to superclass constructor using JavaScript’s apply function Rich Internet Applications2. Core JavaScript #26

Extended prototype chain Rich Internet Applications2. Core JavaScript #27

Subclass example Rich Internet Applications2. Core JavaScript #28

Modules and namespaces JavaScript modules are simply.js files JavaScript does not define language constructs for working with modules Writing modular code is a case of following certain coding conventions Classes are global by default Can create new object to be the namespace for classes within a module Include namespace when calling constructor Rich Internet Applications2. Core JavaScript #29

Namespaces example Rich Internet Applications2. Core JavaScript #30

Are constructors unsafe? Constructors are intended only to be called using the new key word Switches the context (this) to be the object which is being constructed However, there is nothing to stop constructor function being called like any other function, without new Now, context is global Can have unintended consequences… Rich Internet Applications2. Core JavaScript #31

Example of unsafe constructor In a browser, the global context is window object Window has location property, which we change if we forget new Browser will redirect Rich Internet Applications2. Core JavaScript #32

Constructing with a factory Use a method with an explicit return value If called in global context, will call itself in correct context using new, and return result Rich Internet Applications2. Core JavaScript #33

What’s next Client-side JavaScript - putting JavaScript to work in the web browser Rich Internet Applications2. Core JavaScript #34