Objects.  Java Script is an OOP Language  So it allows you to make your own objects and make your own variable types  I will not be going over how.

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

Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Strings.
Session 8 JavaScript/Jscript: Objects Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
EIW: Javascript the Language1 The JavaScript Language.
Javascript Client-side scripting. Up to now  We've seen a little about how to control  content with HTML  presentation with CSS  Javascript is a language.
Chapter 9 Characters and Strings. Topics Character primitives Character Wrapper class More String Methods String Comparison String Buffer String Tokenizer.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
Javascript II Expressions and Data Types. 2 JavaScript Review programs executed by the web browser programs embedded in a web page using the script element.
Tutorial 11 Working with Operators and Expressions
LOGO Document Object Model (DOM)Document Object Model (DOM) Computer Science & Engineering.
JAVA LIBRARY CLASSES CITS Main concepts to be covered Using library classes: String, Math, Color Reading documentation Java 7 API is available.
Using Object-Oriented JavaScript CST 200- JavaScript 4 –
Array Object. he following code creates an Array object called myCars: 1: var myCars=new Array(); // regular array (add an optional integer myCars[0]="Saab";
Variables & Data types Flash ActionScript 3.0 Introduction to Thomas Lövgren, Flash developer
Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel.
Native JavaScript in Hyperion Intelligence Unleashing the Power of Object- Oriented Programming.
CISC474 - JavaScript 03/02/2011. Some Background… Great JavaScript Guides: –
Chapter 3: Data Types and Operators JavaScript - Introductory.
Copyright ©2005  Department of Computer & Information Science Using Number & Math Objects.
JavaScript, Fourth Edition
JavaScript For...In Statement The for...in statement loops through the elements of an array or through the properties of an object. Syntax for (variable.
CHAPTER 4 Java Script อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
RegExp. Regular Expression A regular expression is a certain way to describe a pattern of characters. Pattern-matching or keyword search. Regular expressions.
Chapter 6 Object-Oriented Java Script JavaScript, Third Edition.
SE-1010 Dr. Mark L. Hornick 1 Some Java Classes using & calling methodsS.
INE1020: Introduction to Internet Engineering 3: Web Page Authoring1 Lecture 6: Introduction to Javascript II r Javascript Objects Array String Date Math.
Lecture 9 The Basics of JavaScript Boriana Koleva Room: C54
Java Script: Arrays (Chapter 11 in [2]). 2 Outline Introduction Introduction Arrays Arrays Declaring and Allocating Arrays Declaring and Allocating Arrays.
More on Objects. Goals By the end of this unit you should … … be able to identify selected String properties … be able to identify and use selected String.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Objects.
M. Taimoor Khan Javascript Objects  Every data-type defined in Javascript is an object  It has a class definition for.
Keeping it Neat: Functions and JavaScript Source Files Chapter 7.
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
C Programming – Part 3 Arrays and Strings.  Collection of variables of the same type  Individual array elements are identified by an integer index 
Copyright © Curt Hill Regular Expressions Providing a Search Pattern.
10 – Java Script (3) Informatics Department Parahyangan Catholic University.
CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad GM-IT CIIT Islamabad CIIT Virtual Campus, CIIT COMSATS Institute.
CIS 270—Application Development II Chapter 8—Classes and Objects: A Deeper Look.
Department of Electrical and Computer Engineering Introduction to Perl By Hector M Lugo-Cordero August 26, 2008.
COP 3813 Intro to Internet Computing Prof. Roy Levow Lecture 4 JavaScript.
Unit 11 –Reglar Expressions Instructor: Brent Presley.
INT222 – Internet Fundamentals Week 11: RegExp Object and HTML5 Form Validation 1.
Unit 10-JavaScript Functions Instructor: Brent Presley.
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
1 Predefined Classes and Objects Chapter 3. 2 Objectives You will be able to:  Use predefined classes available in the Java System Library in your own.
JavaScript: Objects 1 © by Pearson Education, Inc. All Rights Reserved.
Tutorial 11 1 JavaScript Operators and Expressions.
Modern JavaScript Develop And Design Instructor’s Notes Chapter 4 – Simple Variable Types Modern JavaScript Design And Develop Copyright © 2012 by Larry.
JavaScript Tutorial. What is JavaScript JavaScript is the programming language of HTML and the Web Programming makes computers do what you want them to.
INTERNET APPLICATIONS CPIT405 JavaScript Instructor: Rasha AlOmari
Regular Expressions In Javascript cosc What Do They Do? Does pattern matching on text We use the term “string” to indicate the text that the regular.
Java Script Date Object
JavaScript.
11 JavaScript: Objects.
Math class Random() method Floor method Top-level parseInt function
Variables and Data Types
SEEM4570 Tutorial 05: JavaScript as OOP
Java Script.
Scope, Objects, Strings, Numbers
JavaScript Syntax and Semantics
JavaScript Functions.
JavaScript Objects.
Chapter 7: Strings and Characters
BY: SITI NURBAYA ISMAIL FACULTY of COMPUTER and MATHEMATICAL SCIENCES
2017, Fall Pusan National University Ki-Joune Li
Tutorial 4 JavaScript as OOP Li Xu
METHODS, CLASSES, AND OBJECTS A FIRST LOOK
Presentation transcript:

Objects

 Java Script is an OOP Language  So it allows you to make your own objects and make your own variable types  I will not be going over how to make your own object  That’s within Ash’s section tomorrow :P

 The Values associated with an object  For instance the Length property of the String object  var txt="Hello World!"; document.write(txt.length);  The output would be 12

 These are the actions that can be performed on the objects  For example the toUpperCase() method of the String object  var str="Hello world!"; document.write(str.toUpperCase());  Here the output would be  HELLO WORLD!

 Creating a Date Object  They are created with the Date() Constructor  There are 4 different ways of instantiating a date 1. new Date() // current date and time 2. new Date(milliseconds) //milliseconds since 1970/01/01 3. new Date(dateString) 4. new Date(year, month, day, hours, minutes, seconds, milliseconds)  Most parameters are optional. If you don’t specify it passes 0

 All dates are calculated in milliseconds from 01 Jan :00:00 Universal Time (UTC) with a day containing 86,400,000 milliseconds  Some examples of instantiating a date  var today = new Date()  var d1 = new Date("October 13, :13:00")  var d2 = new Date(79,5,24)  var d3 = new Date(79,5,24,11,33,0)

 After you create the Date variable you can use get and set methods to manipulate it  For example set a Date object to a specific date. The 14th January 2010  var myDate=new Date(); myDate.setFullYear(2010,0,14);  Set the date to 5 days in to the future  var myDate=new Date(); myDate.setDate(myDate.getDate()+5);  (It is smart enough to know how many days are in a month)

 You are able to compare dates using the Date Object  var myDate=new Date(); myDate.setFullYear(2010,0,14); var today = new Date(); if (myDate>today) { alert("Today is before 14th January 2010"); } else { alert("Today is after 14th January 2010"); }

 Creating the Array  Can be done in 3 ways 1. var myCars=new Array(); // regular array (add an optional integer myCars[0]="Saab"; // argument to control array's size) myCars[1]="Volvo"; myCars[2]="BMW"; 2. var myCars=new Array("Saab","Volvo","BMW"); // condensed array 3. var myCars=["Saab","Volvo","BMW"]; // literal array

 Access  document.write(myCars[0]);  This will output  Saab  Index Starts at 0  Modify:  myCars[0]="Opel";  Changes “Saab” to “Opel”

 Can represent two values:  True  False  var myBoolean=new Boolean();  If the constructor is sent no value or one of these:  0  -0  null  ""  false  undefined  NaN  It is set to False  If it is sent anything else, it is set as true (Even “false”)

 Creating an instance of the Math object  var x=Math.PI; var y=Math.sqrt(16);  8 Mathematical constants to use  Math.E Math.PI Math.SQRT2 Math.SQRT1_2 Math.LN2 Math.LN10 Math.LOG2E Math.LOG10E

 Round()(To the nearest int)  document.write(Math.round(4.7));  This will output 5  Random()  document.write(Math.random());  This outputs a random number between 0 and 1  Floor() (Rounds down)  document.write(Math.floor(50.123)  This will output 50

 An Object that describes a pattern of characters  Used to perforn pattern-matching and “search and replace” funtions  Syntax  var patt=new RegExp(pattern,modifiers); or more simply: var patt=/pattern/modifiers;  pattern specifies the pattern of an expression  modifiers specify if a search should be global, case-sensitive, etc.

 Examples:  To do a case insensitive search for w3schools  var str = "Visit W3Schools";  var patt1 = /w3schools/i;  document.write(str.match(patt1));  Visit W3Schools  To do a global search for “is”  var str="Is this all there is?";  var patt1=/is/g;  document.write(str.match(patt1));  Is this all there is?  To do a global case insensitive search for “is”  var str="Is this all there is?";  var patt1=/is/gi;  document.write(str.match(patt1));  Is this all there is?

 Test() Method  Searches for a specified value within a string and returns a boolean  var patt1=new RegExp("e"); document.write(patt1.test("The best things in life are free"));  Returns true since there is a “e” in the string  Exec() Method  Searches for a specified value within a string and returns the value if found otherwise it returns null  var patt1=new RegExp("e"); document.write(patt1.exec("The best things in life are free"));  Returns “e”