Lesson15. JavaScript Objects Objects encapsulate data (properties) and behavior(methods); the properties and the methods of an object are tied together.

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 FaaDoOEngineers.com FaaDoOEngineers.com.
1 Programmer-Defined Functions Functions allow program modularization Variables declared in function are local variables Only known inside function in.
The Web Warrior Guide to Web Design Technologies
2440: 211 Interactive Web Programming JavaScript Fundamentals.
JavaScript Part for Repetition Statement for statement Cpecifies each of the items needed for counter-controlled repetition with a control variable.
1 Javascrbipt Intro Javascript (or js) is a programming language. Interpreted, not compiled. Not the same as java, but, similar. Use tags to use. Object-oriented.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
HTML Comprehensive Concepts and Techniques Second Edition Project 8 Integrating JavaScript with HTML.
Tutorial 10 Programming with JavaScript
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Functions Part I.
Chapter 6: User-Defined Functions I
Programming Concepts MIT - AITI. Variables l A variable is a name associated with a piece of data l Variables allow you to store and manipulate data in.
 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 10 - JavaScript: Functions Outline 10.1 Introduction 10.2 Program Modules in JavaScript 10.3.
Introduction to scripting
Using Data Active Server Pages Objectives In this chapter, you will: Learn about variables and constants Explore application and session variables Learn.
Javascript and the Web Whys and Hows of Javascript.
4.1 JavaScript Introduction
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Introduction to JavaScript 11 Introduction to Programming the WWW I CMSC Winter 2004 Lecture 14.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
JavaScript: Functions © by Pearson Education, Inc. All Rights Reserved.
Tutorial 2 Variables and Objects. Working with Variables and Objects Variables (or identifiers) –Values stored in computer memory locations –Value can.
Chapter 06 (Part I) Functions and an Introduction to Recursion.
1 JavaScript in Context. Server-Side Programming.
Tutorial 10 Programming with JavaScript. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
Tutorial 8 Programming with ActionScript 3.0. XP Objectives Review the basics of ActionScript programming Compare ActionScript 2.0 and ActionScript 3.0.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Functions.
Using Client-Side Scripts to Enhance Web Applications 1.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 6 September 17, 2009.
XP Tutorial 8 Adding Interactivity with ActionScript.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Functions Outline 5.1Introduction 5.2Program Modules.
C++ Programming Lecture 9 Functions – Part I By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
KIC/Computer Programming & Problem Solving 1.  Introduction  Program Modules in C  Math Library Functions  Functions  Function Definitions  Function.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
JavaScript, Fourth Edition
Chapter 10: JavaScript Functions CIS 275—Web Application Development for Business I.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
1 Functions, Part 1 of 2 Topics Using Predefined Functions Programmer-Defined Functions Using Input Parameters Function Header Comments.
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Introduction into JavaScript Java 1 JavaScript JavaScript programs run from within an HTML document The statements that make up a program in an HTML.
1 JavaScript in Context. Server-Side Programming.
Lesson 16. Practical Application 1 We can take advantage of JavaScript and the DOM, to set up a form so that the first text box of a form automatically.
JavaScript: Functions © by Pearson Education, Inc. All Rights Reserved.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Javascript Overview. What is Javascript? May be one of the most popular programming languages ever Runs in the browser, not on the server All modern browsers.
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.
1 Lesson 6 Introducing JavaScript HTML and JavaScript BASICS, 4 th Edition.
Dale Roberts CSCI N305 Functions Declarations Department of Computer and Information Science, School of Science, IUPUI.
JavaScript and AJAX 2nd Edition Tutorial 1 Programming with JavaScript.
REEM ALMOTIRI Information Technology Department Majmaah University.
Module 1 Introduction to JavaScript
CHAPTER 4 CLIENT SIDE SCRIPTING PART 3 OF 3
JavaScript: Functions
JavaScript Functions.
Introduction to Scripting
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
JavaScript: Functions.
JavaScript What is JavaScript? What can JavaScript do?
Tutorial 10 Programming with JavaScript
JavaScript What is JavaScript? What can JavaScript do?
Chapter 20: Programming Functions
CIS 136 Building Mobile Apps
Functions, Part 1 of 2 Topics Using Predefined Functions
Presentation transcript:

Lesson15

JavaScript Objects Objects encapsulate data (properties) and behavior(methods); the properties and the methods of an object are tied together A set of objects have been defined. Each object encapsulates the elements of an XHTML document and expose to a JavaScript programmer properties and methods that enables a JavaScript program to interact with the elements (objects) in an XHTML document

Objects The browser's window object provides methods and properties that enable a script to manipulate a browser window When a string is assigned to the window object's status property, that string is displayed in the status bar of the browser window. The window object's alert method allows the programmer to display a message in a separate window.

JavaScript Different JavaScript/browser Objects are: String Object Array Object Date Object Math Object Window Object Frame Object Location object Document object –Form Object

JavaScript document.write(" This is Red ") The document is know as an object The write is know as the object's method (an action to be preformed on the object) The double parentheses are called an instance. The text inside of the parentheses is called the method's parameters, or what will do done when the method is acted upon.

JavaScript Methods act upon objects Object properties: A property is like a subsection of an object. It hold specific characteristics about the object. document.write(" The URL of this page is " +document.location+ ".") The + instructs the program to go find the property's value and write it in the space. This script displays an example of an object property. Note: the capitalization pattern of each property. Every time you use these properties the pattern MUST be the same

Functions The best way to develop and maintain a large program is to construct it from small modules. In JavaScript these modules are called Functions. JavaScript programs are written by combining new functions that programmers write with “prepackaged” functions and objects available in JavaScript. The “prepackaged” functions that belong to JavaScript objects are often called Methods. The term Method implies tht the function belongs to a particular object.

Functions Programmers write programmer-defined functions to define specific tasks that may be used at many points in a script. The actual statements defining the function are written only once. A function is invoked by a function call. The function call specifies the function name and provides information (as arguments) that the called function needs to do its task. This allows programs to be modularized. All the variables declared in function definitions are local variables – they are known to the function in which they are defined.

Functions Most functions have parameters. Parameters provide the means for communicating information between functions via function calls. Use functions as building blocks inorder to create new programs. Structured programming and software reusability is important.

Functions The format of a function definition is function function-name ( parameter-list ) { declarations and statements } Function-name  any valid identifier. Parameter-list  list of parameters

Functions return; and return expression; Returns control to the point at which a function was invoked. Examples: The Math object max method determines the larger of its two argument values.

JavaScript With JavaScript, we do not need to specify a main function, like we do for C. You define functions at the beginning of a file (in the head section), and call them and call them anywhere on the page after they are defined. We use the keyword function, and then give the function a meaningful name.

JavaScript Colour change 5 6<!-- hide JavaScript from old browsers 7function changeColour(color) { 8document.bgColor=color; 9} 10// stop hiding JavaScript --> 11 12

Functions

Functions A function with no arguments must include the parentheses: function myfunction() { some statements } By placing functions in the head section of the document, you make sure that all the code in the function has been loaded before the function is called

Functions How to Call a Function A function is not executed before it is called. You can call a function containing arguments: myfunction(argument1,argument2,etc) or without arguments: myfunction()

Function Example function total(a,b) { result=a+b return result } When you call this function you must send two arguments with it: sum=total(2,3)

Review A function is invoked with a ________________ function call A variable known only within the function in which it is defined is called _________________ Local variable

Review The _____________ statement in a called function can be used to pass the value of an expression back to the calling function return a) Method g() { document.writeln( “inside method g” ); } b) function sum( x, y ) { var result; result = x + y } c) Function f( a ); { document.writeln( a ); } a) Method  function b)return x + y c) remove ;