Lecture 16

Lecture 16 - function <name> (...

Info iconThis preview shows pages 1–33. Sign up to view the full content.

View Full Document Right Arrow Icon
CS170 Computer Applications for Business Fall 2008 Instructor: Kristian Stout Lecture 16 Functions and Examples Readings: Chapter 20
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Javascript Advanced Topics An advanced array technique user-defined functions examples
Background image of page 2
Array Advanced Techniques: Strings as Indexes You can use a string instead of a simple number index - we often call this a hash for example: var myArray = []; myArray[“red”] = “#FF0000”; myArray[“green”] = “#00FF00”; myArray[“blue”] = “#0000FF”; we can use this technique for things like “lookup tables”
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
User Defined Functions Functions are “packages” for algorithms 3 parts - Name: the 'identifier'; commonly is descriptive eg function addTwoNumbers() {} - Parameters values we pass INTO functions - Definition the actual code performed. may or may not have a “return value” You are familiar with some “built in” functions - eg: alert(); String.charAt(); String.toUpperCase() Math.Random()
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
User Defined Functions (cont) Syntax:
Background image of page 6
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 8
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 10
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 12
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 14
Background image of page 15

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 16
Background image of page 17

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 18
Background image of page 19

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 20
Background image of page 21

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 22
Background image of page 23

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 24
Background image of page 25

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 26
Background image of page 27

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 28
Background image of page 29

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 30
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: function <name> ( <parameter list> ){ <statement list> } To make a function execute it's code, we write it's name and specify parameters like:-myFunc(myVar1, myVar2); Variable Scope in Functions Scope of a name defines how far from its declarations it can be used Local vs Global-local variables can only be used inside the function that declared them-global variables can be used throughout the program If you need to reuse information in different functions and other parts of a program you need global variables Fancy-ness: Call a function from a link Your JS does not have to start running when the page loads-user events can start the ball rolling We can have javascript start as a result of a number of things-button click-hyperlink click-even a mouse click-many many more events simplest way: use the javascript: style link-eg <a href='javascript:alert(wow!)'>wow!</a>...
View Full Document

This note was uploaded on 02/07/2011 for the course COMP 178 taught by Professor Stout during the Fall '08 term at Rutgers.

Page1 / 33

Lecture 16 - function <name> (...

This preview shows document pages 1 - 33. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online