[Robert W. Sebesta, “Programming the World Wide Web

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

1 CSCE 1030 Computer Science 1 Introduction to Object Oriented Programming.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
The Web Warrior Guide to Web Design Technologies
Advanced JS The World's Most Misunderstood Programming Language ) Douglas Crockford( Shimon Dahan
Wednesday, 10/2/02, Slide #1 CS 106 Intro to CS 1 Wednesday, 10/2/02  QUESTIONS (on HW02 – due at 5 pm)??  Today:  Review of parameters  Introduction.
Road Map Introduction to object oriented programming. Classes
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Chapter 3 Using Classes and Objects. 2 Creating Objects  A variable holds either a primitive type or a reference to an object  A class name can be used.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
OOP Spring 2006 – Recitation 31 Object Oriented Programming Spring 2006 Recitation 3.
Introduction to Classes and Objects CS-2303, C-Term Introduction to Classes and Objects CS-2303 System Programming Concepts (Slides include materials.
Object Oriented Software Development
Why to Create a Procedure
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.
Tutorial 2 Variables and Objects. Working with Variables and Objects Variables (or identifiers) –Values stored in computer memory locations –Value can.
ALBERT WAVERING BOBBY SENG. Week 4: JavaScript  Quiz  Announcements/questions.
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Classes In C++ 1. What is a class Can make a new type in C++ by declaring a class. A class is an expanded concept of a data structure: instead of holding.
JavaScript Syntax, how to use it in a HTML document
Chapter 4 Introduction to Classes, Objects, Methods and strings
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Static. 2 Objectives Introduce static keyword –examine syntax –describe common uses.
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
Introduction into JavaScript Java 1 JavaScript JavaScript programs run from within an HTML document The statements that make up a program in an HTML.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
April 20, 1998CS102-02Lecture 4-1 A Method to the Madness CS Lecture 4-1 Java's Work Horses.
MIT-AITI: Functions Defining and Invoking Functions Functions as Data Function Scope: The call Object Function Arguments: The arguments objects Function.
Object Oriented Programming and Data Abstraction Rowan University Earl Huff.
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,
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 7: Introduction to Object- Oriented Programming in Python – Exercises Xiang Lian The University of.
Introduction to Classes and Objects CS-2303, C-Term C++ Program Structure Typical C++ Programs consist of:– main –A function main –One or more classes.
CHAPTER 1 THE ABC OF PROGRAMMING B HOW DO COMPUTERS FIT IN WITH THE WORLD AROUND THEM?
Eine By: Avinash Reddy 09/29/2016.
Test 2 Review Outline.
>> JavaScript: Location, Functions and Objects
“Under the hood”: Angry Birds Maze
Structures Revisited what is an aggregate construct? What aggregate constructs have we studied? what is a structure? what is the keyword to define a structure?
3 Introduction to Classes and Objects.
Structures Revisited what is an aggregate construct? What aggregate constructs have we studied? what is a structure? what is the keyword to define a structure?
Scope, Objects, Strings, Numbers
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
The structure of computer programs
Object-Oriented Programming: Classes and Objects
Methods The real power of an object-oriented programming language takes place when you start to manipulate objects. A method defines an action that allows.
Chapter 3 Introduction to Classes, Objects Methods and Strings
PHP.
T. Jumana Abu Shmais – AOU - Riyadh
CHAPTER 1 THE ABC OF PROGRAMMING
Object Oriented Programming in java
Functions, Regular expressions and Events
CS5220 Advanced Topics in Web Programming JavaScript Basics
CS 1111 Introduction to Programming Fall 2018
Tonga Institute of Higher Education
Fundaments of Game Design
Object Oriented Programming in java
JavaScript CS 4640 Programming Languages for Web Applications
[Robert W. Sebesta, “Programming the World Wide Web
Introducing JavaScript
PHP an introduction.
[Based in part on SWE 432 and SWE 632 materials by Jeff Offutt, GMU]
Web Software Model CS 4640 Programming Languages for Web Applications
Classes and Objects Systems Programming.
JavaScript CS 4640 Programming Languages for Web Applications
SPL – PS3 C++ Classes.
Introduction to Classes and Objects
Presentation transcript:

JavaScript: Functions, methods and objects CS 4640 Programming Languages for Web Applications [Robert W. Sebesta, “Programming the World Wide Web Jon Duckett, Interactive Frontend Web Development]

Functions Similar to Java functions but header is somewhat different Return type not specified (like PHP, since JS has dynamic typing) Parameter types also not specified Functions execute when they are called, just as in any language

Anonymous Functions and Function Expressions Functions can be assigned to variables Variables declared in a function are local to the function Parameters are all value No parameter type-checking “Function expression” [see jex3.html]

Immediately Invoked Function Expressions Anonymous functions can be executed once as the interpreter comes across them Grouping operators tell the interpreter to treat this as an expression Parentheses tell the interpreter to call the function immediately

Functions and Default Values (ES6)

Global and Local Scopes (function-level scope) Global scope Naming collision Two JavaScript files, both have a global variable with the same name

How do Web Apps fit in with the World Around Them? revisit How do Web Apps fit in with the World Around Them? Objects group variables and functions to create a model representing something you would recognize from the real world Object type: Hotel Event Happens when Method called Reserve reservation is made makeReservation() Cancel reservation is cancelled cancelReservation() Method What it does makeReservation() increases value of bookings property cancelReservation() decreases value of bookings property checkAvailability() subtracts value of bookings property from value of rooms property and returns number of rooms available Properties Name: Awesome Rating: 5 Rooms: 70 Bookings: 56 Pool: true Gym: true Events are things or interactions that can happen to the objects Properties tell us the characteristics of the objects Methods represent tasks that are associated with the objects (or things we can do with the objects) Object type: Car Event Happens when Method called Break driver slows down changeSpeed() Accelerate driver speeds up changeSpeed() Method What it does changeSpeed() increases or decreases value of currentSpeed property Properties Make: UVA1 currentSpeed: 30 Color: yellow Fuel: gasoline

JavaScript Objects JavaScript is an object-based language It supports for object-oriented programming but not at the same level as other languages (ES6: introduced class – still lacks private property) Objects are represented as property-value pair The property values can be data or functions (methods) A property is something that can be modified : Data properties : primitive values or references to objects Method properties : can be executed Objects can be created and their properties can be changed dynamically JS is not really typed .. If it doesn’t care between a number and a string, why care between two kinds of objects?

Creating Objects Create an object and assign variables and functions directly by using { } syntax

Creating Objects with Constructors Create an instance of the object using the constructor function and the new keyword

Accessing Objects Access properties or methods of an object using dot notation Access properties or methods using square brackets

Updating Properties Update properties using dot notation Update properties using square brackets

Adding Properties Add a property using a dot notation

Deleting Properties Delete a property using the delete keyword