6.1 JavaScript Objects and Object- Oriented Programming (OOP)

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Introduction to Ruby.
Advertisements

JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
COP 2800 Lake Sumter State College Mark Wilson, Instructor.
1 MATH METHODS THAT RETURN VALUES. 2 JAVA'S MATH CLASS.
Intro to JavaScript. JavaScript History Client (generally browser-side) language invented at Netscape under the name LiveScript around 1995 Netscape wanted.
Return values.
Self Check 1.Which are the most commonly used number types in Java? 2.Suppose x is a double. When does the cast (long) x yield a different result from.
Pemrograman Dasar - Data Types1 OPERATOR. Pemrograman Dasar - Data Types2 Arithmetic operator  + - * /  / operator denotes integer division if both.
Session 8 JavaScript/Jscript: Objects Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
Warm-up: Tuesday, March 11  In programming, what is the difference between an object and a class?
1 A Balanced Introduction to Computer Science, 2/E David Reed, Creighton University ©2008 Pearson Prentice Hall ISBN Chapter 17 JavaScript.
CS 211 Inheritance AAA.
Databases Lab 5 Further Select Statements. Functions in SQL There are many types of functions provided. The ones that are used most are: –Date and Time.
Fundamental Programming Structures in Java: Strings.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
ASP.NET Programming with C# and SQL Server First Edition
Introduction to MATLAB
 2004 Prentice Hall, Inc. All rights reserved. Chapter 12 - JavaScript: Objects Outline 12.1 Introduction 12.2 Thinking About Objects 12.3 Math Object.
1 CS101 Introduction to Computing Lecture 38 String Manipulations (Web Development Lecture 13)
6. JavaScript Objects and Object- Oriented Programming (OOP)
Lesson 3 – Regular Expressions Sandeepa Harshanganie Kannangara MBCS | B.Sc. (special) in MIT.
Using Data Active Server Pages Objectives In this chapter, you will: Learn about variables and constants Explore application and session variables Learn.
Computer Science 121 Scientific Computing Winter 2014 Chapter 3 Simple Types: Numbers, Text, Booleans.
Scripting Languages.
1 JavaScript: Objects and Object Models October 25, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel,
JavaScript, Fourth Edition
Chapter 6 Object-Oriented Java Script JavaScript, Third Edition.
The java.lang Package chapter 8 Java Certification Study Group February 2, 1998 Seth Ladd.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Objects.
A Balanced Introduction to Computer Science, 3/E David Reed, Creighton University ©2011 Pearson Prentice Hall ISBN Chapter 15 JavaScript.
An Introduction to Java Programming and Object-Oriented Application Development Chapter 7 Characters, Strings, and Formatting.
Calculations Chapter 11 Library of math functions, and constants cos, sin, tan, abs, min, max, log, random, sqrt, pow, exp Constants.PI,.E Use care with.
4.4 JavaScript (JS) Deitel Ch. 7, 8, 9, JavaScript & Java: Similarities JS (JavaScript) is case-sensitive Operators –arithmetic: unary +, unary.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Chapter 7: Characters, Strings, and the StringBuilder.
Department of Electrical and Computer Engineering Introduction to C++: Primitive Data Types, Libraries and Operations By Hector M Lugo-Cordero August 27,
Project 1: Using Arrays and Manipulating Strings Essentials for Design JavaScript Level Two Michael Brooks.
Geoff Holmes Date Math Weighted Distr Strings String methods Tokenizers System Examples Utility Classes (Chapter 17) import java.util.*;
Introduction As programmers, we don’t want to have to implement functions for every possible task we encounter. The Standard C library contains functions.
Chapter 3: Classes and Objects Java Programming FROM THE BEGINNING Copyright © 2000 W. W. Norton & Company. All rights reserved Java’s String Class.
String String Builder. System.String string is the alias for System.String A string is an object of class string in the System namespace representing.
CSC Programming I Lecture 9 September 11, 2002.
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Introduction to Object Oriented Programming (OOP) Object Oriented programming is method of programming.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming strings.
CPS120: Introduction to Computer Science Lecture 16 Data Structures, OOP & Advanced Strings.
JavaScript: Objects 1 © by Pearson Education, Inc. All Rights Reserved.
Declaring variables The type could be: int double char String name is anything you want like lowerCaseWord.
Matlab Tutorial Iman Moazzen First Session – September 11, 2013.
CIS Intro to JAVA Lecture Notes Set 5 26-May-05.
Modern JavaScript Develop And Design Instructor’s Notes Chapter 4 – Simple Variable Types Modern JavaScript Design And Develop Copyright © 2012 by Larry.
Introduction to Python Developed by Dutch programmer Guido van Rossum Named after Monty Python Open source development project Simple, readable language.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
© 2006 Pearson Education Chapter 2: Objects and Primitive Data Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition by.
1 A Balanced Introduction to Computer Science, 2/E David Reed, Creighton University ©2008 Pearson Prentice Hall ISBN Chapter 15 JavaScript.
© 2007 D. J. ForemanJS-m1 String, Math & Miscellaneous Methods & Properties.
Java Script: Objects (Chapter 12 in [2]). 2 Outline Introduction Introduction Thinking About Objects Thinking About Objects Math Object Math Object String.
11 JavaScript: Objects.
Object Oriented Programming
JavaScript Objects.
Multiple variables can be created in one declaration
Lecture 4 Using Classes Richard Gesick.
String Objects & its Methods
Chapter 7: Strings and Characters
String, Math & Miscellaneous Methods & Properties
JavaScript: Objects.
Chapter 17 JavaScript Arrays
Introduction to MATLAB
String, Math & Miscellaneous Methods & Properties
11 JavaScript: Objects.
What We Want To Do User enters: Mary Smith
Presentation transcript:

6.1 JavaScript Objects and Object- Oriented Programming (OOP)

2 Motto: My object all sublime I shall achieve in time. —W. S. Gilbert

3 JavaScript & OOP JavaScript is object-oriented –even if you don’t realize it –there is a “global object” all global variables and functions are its properties –there are predefined JS objects –you can add variables and functions to an object's "prototype" (aka classe) –you can – and should define your own objects

4 JavaScript Objects Objects have –a type the type has a name –attributes properties –behaviors functions in JavaScript, functions are properties, too!

5 Object-Oriented design Uses software models that define objects similar the real- world objects in the problem domain Uses classes for objects that have the same characteristics Uses inheritance to derive a new classes of objects from existing classes by adding their own unique characteristics Models communication between objects Encapsulates attributes and behaviors of objects by restricting their visibility to outside objects Allows to redefine the behaviors of derived objects - polymorphism Is a natural and intuitive way to view software design

6 Procedural vs. OOP Procedural programmers concentrate on writing functions –actions that perform a task are composed within functions –a set of functions forms a program Object-oriented programmers concentrate on creating classes of objects –a class contains data and functions that provide services to clients –a set of classes forms a program

7 Advantages of OOP A class is to its objects as cookie-cutter is to cookies OOP make you think in categories OOP make you tackle large problems in terms of smaller sub-problems Classes make it possible to reuse them in other projects With OOP, you can build much of new software by combining existing classes

8 Standard Objects: Math Math defines methods for most common mathematical calculations –the methods are very similar to those in Java java.lang.Math –constants PI, E, LN2, LN10, SQRT2, SQRT1_2 c LOG2E, LOG10E –methods sqrt(), sin(), cos(), tan(), atan(), exp(), log(), pow() ceil(), floor(), round(), max(), min()

9 Standard Objects: String A string is a series of characters –as in Java: letters, digits, special characters Unicode characters same notation – \n, \t, \f, \c, \", \', \\ String constants –can be enclosed either in "" or in '' concatenation operator + –any type concatenated with a string will be converted to a string –using its toString() method property length –holds the number of characters in the string

10 String Methods charAt(index) –returns the character at index –Indices start at 0 and go to length-1 –returns an empty string if index >= length charCodeAt(index) –returns the Unicode value of the character at index –returns NaN if index >= length toLowerCase() –returns the lowercase version of the string toUpperCase() –returns the uppercase version of the string indexOf(pattern[,startIndex]) –returns the beginning index of the first occurrence of pattern –returns -1 if pattern is not found –starts search at startIndex if it is given lastIndexOf(pattern[,startIndex]) –returns the beginning index of the last occurrence of pattern –returns -1 if pattern is not found –starts search at startIndex if it is given

11 String Methods (cont.) split(pattern) –breaks a string into token strings delimited by pattern –returns an array of the tokens substring(from[,to]) –returns the substring starting at from index up to to index –ends the string returned at length-1 if to >= length fixed() –returns this string wrapped into strike() –returns this string wrapped into sub() –returns this string wrapped into sup() –returns this string wrapped into link(url) –returns this string wrapped into anchor(anchor) –returns this string wrapped into