INFM 603: Information Technology and Organizational Context Jimmy Lin The iSchool University of Maryland Thursday, October 9, 2014 Session 5: JavaScript.

Slides:



Advertisements
Similar presentations
Order of complexity. Consider four algorithms 1.The naïve way of adding the numbers up to n 2.The smart way of adding the numbers up to n 3.A binary search.
Advertisements

College of Information Technology & Design
INFM 603: Information Technology and Organizational Context Jimmy Lin The iSchool University of Maryland Thursday, September 19, 2013 Session 3: JavaScript.
The Web Warrior Guide to Web Design Technologies
JavaScript Functions, Objects, Array, and Control Structures Dr. Charles Severance
INFM 603: Information Technology and Organizational Context Jimmy Lin The iSchool University of Maryland Thursday, September 13, 2012 Session 2: HTML and.
CLASSES & OBJECTS Representin’ real-world things in code-space Brian Camodeca, Mercyhurst College.
CS 106 Introduction to Computer Science I 11 / 09 / 2007 Instructor: Michael Eckmann.
Introduction to Programming with Java, for Beginners Intro OOP with Java Java Program Structure.
Web Infrastructure Week 3 INFM 603. The Key Ideas Questions Structured Programming Modular Programming Data Structures Object-Oriented Programming.
LBSC 690 Session #10 Programming, JavaScript Jimmy Lin The iSchool University of Maryland Wednesday, November 5, 2008 This work is licensed under a Creative.
Data Structures Week 4 INFM 603. The Key Ideas Structured Programming  Modular Programming  Data Structures Object-Oriented Programming.
LBSC 690: Session 10 Programming, JavaScript Jimmy Lin College of Information Studies University of Maryland Monday, November 12, 2007.
25-Jun-15 JavaScript Language Fundamentals II. 2 Exception handling, I Exception handling in JavaScript is almost the same as in Java throw expression.
CS 106 Introduction to Computer Science I 03 / 30 / 2007 Instructor: Michael Eckmann.
 Last lesson  Arrays for implementing collection classes  Performance analysis (review)  Today  Performance analysis  Logarithm.
Elementary Data Structures and Algorithms
Fall 2007CSE 115/503 Introduction to Computer Science for Majors I1 End of Week Five! Questions? First part of essay assignment (choosing a topic) is posted.
CS 106 Introduction to Computer Science I 03 / 17 / 2008 Instructor: Michael Eckmann.
Search Lesson CS1313 Spring Search Lesson Outline 1.Searching Lesson Outline 2.How to Find a Value in an Array? 3.Linear Search 4.Linear Search.
PHP Workshop ‹#› PHP Classes and Object Orientation.
INFM 603: Information Technology and Organizational Context Jimmy Lin The iSchool University of Maryland Wednesday, March 26, 2014 Session 8: Ajax and.
Objects and Events Week 5 INFM 603. Muddiest Points Commonly used functions.getElementById Recursion Hashing.
JS Arrays, Functions, Events Week 5 INFM 603. Agenda Arrays Functions Event-Driven Programming.
Creating scalars, vectors, matrices Ex1 & 2. Dot Product & Cross Product Ex3. Plotting Graphs Ex4. Conversion Table Ex5. Plotting functions Finishing Ex4.
INFM 603: Information Technology and Organizational Context Jimmy Lin The iSchool University of Maryland Thursday, October 18, 2012 Session 7: PHP.
Test 2 Part a You have 20 minutes Don’t forget to put your name on the test Closed book No computers Do your own work.
INFM 603: Information Technology and Organizational Context Jimmy Lin The iSchool University of Maryland Wednesday, February 5, 2014 Session 2: HTML and.
Parallel Algorithms Sorting and more. Keep hardware in mind When considering ‘parallel’ algorithms, – We have to have an understanding of the hardware.
Arrays – What is it? – Creation – Changing the contents Functions – What is it? – Syntax – How they work – Anonymous functions A quick lesson in Objects.
Review IDIA 619 Spring 2013 Bridget M. Blodgett. HTML A basic HTML document looks like this: Sample page Sample page This is a simple sample. HTML user.
CS 102 Computers In Context (Multimedia)‏ 01 / 23 / 2009 Instructor: Michael Eckmann.
Introduction to JavaScript 41 Introduction to Programming the WWW I CMSC Winter 2004 Lecture 17.
Chapter 2 Array Data Structure Winter Array The Array is the most commonly used Data Storage Structure. It’s built into most Programming languages.
SEARCHING. Vocabulary List A collection of heterogeneous data (values can be different types) Dynamic in size Array A collection of homogenous data (values.
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
20-753: Fundamentals of Web Programming 1 Lecture 12: Javascript I Fundamentals of Web Programming Lecture 12: Introduction to Javascript.
ClassesPHPMay-2007 : [‹#›] PHP Classes and Object Orientation.
Functions, Objects, and Programming IDIA 619 Spring 2014 Bridget M. Blodgett.
Computers and Scientific Thinking David Reed, Creighton University Functions and Libraries 1.
Classes and Objects in Java
Lecture # 13 JavaScript Functions: A Trip to the Grocery Store.
1 JavaScript Functions and Objects. 2 Objectives You will be able to Use JavaScript functions in JavaScript scripts. Get JavaScript functions executed.
1 5. Abstract Data Structures & Algorithms 5.6 Algorithm Evaluation.
JavaScript: The First Parts Part One Douglas Crockford Yahoo! Inc.
1 JavaScript Part 3. Functions Allow the user to decide when a particular script should be run by the browser in stead of running as long as the page.
Manish K Parmar PGT (CS) K V VVNagar Thursday, December 24, 2015 Lesson on USER DEFINED FUNCTION IN C++ Presented by Manish K Parmar PGT Computer Science.
New Mexico Computer Science For All Search Algorithms Maureen Psaila-Dombrowski.
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.
Searching Topics Sequential Search Binary Search.
INFM 603: Information Technology and Organizational Context Jimmy Lin The iSchool University of Maryland Wednesday, February 19, 2014 Session 4: JavaScript.
Searching CSE 103 Lecture 20 Wednesday, October 16, 2002 prepared by Doug Hogan.
 We have created our two separate 'person' objects, we can set their properties using the methods (the setters) we created.  class person {  var $name;
1 Agenda  Unit 8: Programs and Data. 2 Structured data - Array There are many situations where we want to apply the same processing to a collections.
What is an object?. What Makes an Object? An object has identity (it acts as a single whole). Every object has a name that identifies what it is. Ex.
1 5. Abstract Data Structures & Algorithms 5.6 Algorithm Evaluation.
Classes and Objects in Java
Modern JavaScript Develop And Design
Lecture 2: Introduction to Algorithms
Searching CSCE 121 J. Michael Moore.
Algorithm design and Analysis
Searching, Sorting, and Asymptotic Complexity
CLASSES, AND OBJECTS A FIRST LOOK
The structure of programming
Sum this up for me Let’s write a method to calculate the sum from 1 to some n public static int sum1(int n) { int sum = 0; for (int i = 1; i
The structure of programming
Classes and Objects in Java
Thinking procedurally
Presentation transcript:

INFM 603: Information Technology and Organizational Context Jimmy Lin The iSchool University of Maryland Thursday, October 9, 2014 Session 5: JavaScript – Functions and Objects

Source: The Matrix It’ll all make sense today…

Source: Iron Chef America Programming… is a lot like cooking!

Functions Reusable code for performing a computation A function… Takes in one or more parameters (or arguments) Executes some code Optionally returns a value

Anatomy of Functions function convertToCelsius(f) { var celsius = 5/9 * (f-32); return celsius; } function weirdAddition(a, b) { var result = a + b - 0.5; return result; } name of the function list of parameters return value

Using Functions Calling functions invokes the set of instructions it represents Parameters to the function are specified between the parens Multiple arguments are separated by commas c = convertToCelsius(60); function convertToCelsius(f) { var celsius = 5/9 * (f-32); return celsius; } argument to the function

More Examples var r = weirdAddition(2, 4); var a = 2; var b = 3; var s = weirdAddition(a, b); function weirdAddition(a, b) { var result = a + b - 0.5; return result; }

You’ve already been doing it! Built in functions: prompt("enter some text", "default"); alert("message here"); Message handlers!

Cooking analogy?

Objects It’s just a collection of properties! var fido = { name: "Fido", weight: 40, breed: "Mixed", loves: ["walks", "fetching balls"] };

Objects and Properties Access object properties using the “dot” notation Where have we seen this before? var w = fido.weight; fido.breed = "Yellow Lab"; Wine demo (Part 1)

Objects: Methods It’s just a collection of properties! Objects can have functions also! (called methods) var fido = { name: "Fido", weight: 40, breed: "Mixed", loves: ["walks", "fetching balls"], bark: function() { alert("Woof woof!"); } };

Calling a Method Invoke an object’s method using the dot notation: It’s just like a function call! Where have you seen this before? What’s “this”? fido.bark();

What’s the point? Claim: every method can be rewritten as a ordinary function, and vice versa? Why have methods? What’s the advantage of functions directly to objects? Wine demo (Part 2)

Constructor! So far, building objects is a tedious process… that’s where constructors come in: function Dog(name, breed, weight) { this.name = name; this.breed = breed; this.weight = weight; this.bark = function() { if (this.weight > 25) { alert(this.name + " says Woof!"); } else { alert(this.name + " says Yip!"); } }; }

Using Constructors Invoke constructors using “new”: Wine demo (Part 3) var fido = new Dog("Fido", "Mixed", 38); var tiny = new Dog("Tiny", "Chawalla", 8); var clifford = new Dog("Clifford", "Bloodhound", 65); fido.bark(); tiny.bark(); clifford.bark();

Source: The Matrix It’ll all make sense today…

Source: The Matrix Make sense now?

Okay, you can relax now… Source: Flickr

Source: The Matrix (a bit) more of this…

What happens if a function calls itself? Source: Wikipedia

How do we find an element in a sorted list of elements? How do we quantify the speed of various algorithms?

Sequential Search Source: Wikipedia

Binary Search Source: Wikipedia

Algorithmic Complexity Linear vs. logarithmic algorithms Matters as data sizes increase!