Introduction to Web Tech and Programming

Similar documents
JAVASCRIPT. JavaScript is the programming language of HTML and the Web. JavaScript Java. JavaScript is interpreted by the browser.

Client-Side Web Technologies. JavaScript Part I

Javascript Arrays, Object & Functions

XML JavaScript Object Notation JSON Cookies Miscellaneous What Javascript can t do. OOP Concepts of JS

ID1354 Internet Applications

Such JavaScript Very Wow

CITS1231 Web Technologies. JavaScript Math, String, Array, Number, Debugging

PEMROGRAMAN BERORIENTASI OBJECT. Indra Gunawan, ST., M.Kom., CEH., CHFI

Lecture 3: The Basics of JavaScript. Background. Needs for Programming Capability. Origin of JavaScript. Using Client-side JavaScript

CSC Web Programming. Introduction to JavaScript

COMS 469: Interactive Media II

JavaScript. History. Adding JavaScript to a page. CS144: Web Applications

Game Scripting. Overview. Scripting Concepts. Script Interpreters ( Engines ) Scripting Languages

University Convocation IT 3203 Introduction to Web Development Creating Objects Accessing Property Values

Basics of JavaScript. Last Week. Needs for Programming Capability. Browser as Development Platform. Using Client-side JavaScript. Origin of JavaScript

Produced by. App Development & Modelling. BSc in Applied Computing. Eamonn de Leastar

JavaScript CS 4640 Programming Languages for Web Applications

COMP519 Web Programming Lecture 12: JavaScript (Part 3) Handouts

JavaScript CS 4640 Programming Languages for Web Applications

JavaScript. History. Adding JavaScript to a page. CS144: Web Applications

Web Application Development

Node.js Training JavaScript. Richard richardrodger.com

Princess Nourah bint Abdulrahman University. Computer Sciences Department

Darshan Institute of Engineering & Technology for Diploma Studies Unit 2. 2 Working with JavaScript

JavaScript: Coercion, Functions, Arrays

SEEM4570 System Design and Implementation Lecture 03 JavaScript

JavaScript: Objects, Methods, Prototypes

CSS The web browser uses its own resources, and eases the burden on the server. It has fewer features than server side scripting.

UNIT -II. Language-History and Versions Introduction JavaScript in Perspective-

Chapter 3 Data Types and Variables

JavaScript. Training Offer for JavaScript Introduction JavaScript. JavaScript Objects

Introduction to JavaScript p. 1 JavaScript Myths p. 2 Versions of JavaScript p. 2 Client-Side JavaScript p. 3 JavaScript in Other Contexts p.

More on JavaScript Functions

Kotlin for Android developers

COMP519 Web Programming Lecture 14: JavaScript (Part 5) Handouts

a Why JavaScript? jonkv interactivity on the web CGI JavaScript Java Applets Netscape LiveScript JavaScript 1: Example

Programming II (CS300)

JavaScript Introduction

The JavaScript Language

COMS W3101: SCRIPTING LANGUAGES: JAVASCRIPT (FALL 2017)

The JavaScript Language

JavaScript Basics. Mendel Rosenblum. CS142 Lecture Notes - JavaScript Basics

Object Oriented Programming

JavaScript: Sort of a Big Deal,

JavaScript. The Basics

Object Oriented Programming

String. Other languages that implement strings as character arrays

JavaScript for C# Programmers Kevin

Lab 14 & 15: String Handling

Produced by. Agile Software Development. Eamonn de Leastar

JavaScript Functions, Objects and Array

710 Index Attributes, 127 action attribute, 263 assigning, bottom attribute, domain name attribute, 481 expiration date attribute, 480 8

Instructor s Notes Web Programming JavaScript Functions. Web Programming JavaScript Functions

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

TypeScript. Types. CS144: Web Applications

Administration. Objects and Arrays. Objects. Agenda. What is an Object? What is a Class?

Symbols. accessor properties, attributes, creating, adding properties, 8 anonymous functions, 20, 80

15.1 Origins and Uses of Ruby

So, if you receive data from a server, in JSON format, you can use it like any other JavaScript object.

Xtend Programming Language

CSc 337 LECTURE 5: GRID LAYOUT AND JAVASCRIPT

Javascript Methods. concat Method (Array) concat Method (String) charat Method (String)

CSCE 120: Learning To Code

JavaScript. IT Engineering I Instructor: Ali B. Hashemi

JavaScript. Why JavaScript? Dynamic Form Validation. Online calculator. IT Engineering I Instructor: Ali B. Hashemi. Interaction

CMSC131. Inheritance. Object. When we talked about Object, I mentioned that all Java classes are "built" on top of that.

LECTURE-2. Functions review HTML Forms. Arrays Exceptions Events. CS3101: Scripting Languages: Javascript Ramana Isukapalli

CS1520 Recitation Week 2

CS 2340 Objects and Design - Scala

JavaScript or: How I Learned to Stop Worrying and Love a Classless Loosely Typed Language

JScript Reference. Contents

They grow as needed, and may be made to shrink. Officially, a Perl array is a variable whose value is a list.

Ruby: Introduction, Basics

Web Engineering (Lecture 06) JavaScript part 2

JavaScript Basics. The Big Picture

CS1150 Principles of Computer Science Objects and Classes

JavaScript Syntax. Web Authoring and Design. Benjamin Kenwright

5/23/2015. Core Java Syllabus. VikRam ShaRma

Chapter 4 Basics of JavaScript

JAVASCRIPT - OBJECTS OVERVIEW

COMP284 Scripting Languages Lecture 15: JavaScript (Part 2) Handouts

Lecture 8 (7.5?): Javascript

WINTER. Web Development. Template. PHP Variables and Constants. Lecture

Outcomes Week 2 Overview Describe the inputs, activities, and outputs of each step in the software development life cycle. Describe arithmetic, relati

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)

About the Tutorial. Audience. Prerequisites. Copyright and Disclaimer

Produced by. Agile Software Development. Eamonn de Leastar

Arrays Structured data Arrays What is an array?

Lecture 7 Objects and Classes

Lesson 9: Custom JavaScript Objects

Introduction to JSON. Roger Lacroix MQ Technical Conference v

Web Programming and Design. MPT Junior Cycle Tutor: Tamara Demonstrators: Aaron, Marion, Hugh

JavaScript or: HOW I LEARNED TO STOP WORRYING AND LOVE A CLASSLESS*

The Number object. to set specific number types (like integer, short, In JavaScript all numbers are 64bit floating point

3 The Building Blocks: Data Types, Literals, and Variables

3.1 Class Declaration

1. Introduction. 2. Scalar Data

Inheritance. Transitivity

Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4.

Transcription:

Introduction to Web Tech and Programming

Objects Objects Arrays

JavaScript Objects Objects are an unordered collection of properties. Basically variables holding variables. Have the form name : value name is always String. value can be primitive or object

JavaScript Objects JavaScript has two types of values Primitives (String, Number, Boolean, etc.) Objects String* Number* Boolean* Date Math Regular Arrays Functions Objects

JavaScript Objects Examples var person = {firstname:"mike", lastname:"jones"}; var car = {make: "Honda", model: "Civic", enginesize: 2000}

Creating JavaScript Objects Define and create a single object using an object literal Define and create a single object using the new keyword Define an object constructor, and then create objects of the constructed type

Creating JavaScript Objects Define and create a single object using an object literal var person = {firstname:"mike", lastname:"jones", height:6.2};

Creating JavaScript Objects Define and create a single object using the new keyword var person = new Object(); person.firstname = "Mike"; person.lastname = "Jones"; person.height = 6.2;

Creating JavaScript Objects Define an object constructor, and then create objects of the constructed type function person(first, last, height) { } this.firstname = first; this.lastname = last; this.height = height; var myfather = new person("mike", "Jones", 6.2); var mymother = new person("manna", "Jones", 5.6);

The this Keyword this is a reference (keyword, not a variable) to the object that owns the currently executing JavaScript code In a function it refers to the object that owns the function In an object, it refers to the object itself Does not have a value in an object constructor, value substituted for new object

JavaScript's Built-in Constructors Available constructors var obj1 = new Object(); // A new Object object var obj2 = new String(); // A new String object var obj3 = new Number(); // A new Number object var obj4 = new Boolean() // A new Boolean object var obj5 = new Date(); // A new Date object var obj6 = new Array(); // A new Array object var obj7 = new RegExp(); // A new RegExp object var obj8 = new Function(); // A new Function object Math is a global object, and does not have a constructor

JavaScript Object Literals Object literals are more efficient var x1 = {}; // new object var x2 = ""; // new primitive string var x3 = 0; // new primitive number var x4 = false; // new primitive boolean var x5 = []; // new array object var x6 = /()/ // new regexp object var x7 = function(){}; // new function object

JavaScript Object Properties Accessing objectname.property objectname["property"] objectname[expression]

For In Loops The JavaScript for-in statement loops through the properties of an object Example var person = {fname:"john", lname:"doe", age:25}; var text = ""; var x; for (x in person) { } text += person[x];

Object Properties You can add new properties to an existing object by simply giving it a value person.haircolor = "Beige" You can delete properties using the delete keyword var person = {firstname:"john", lastname:"doe", age:50, eyecolor:"blue"}; delete person.age; // or delete person["age"];

Object Methods Methods are actions that performed on object Object properties can be functions An object method is an object property containing a function Syntax methodname : function() { code lines }

Object Methods Built in methods var message = "Hello world!"; var x = message.touppercase(); alert(x); // Message dialog displays HELLO WORLD!

Adding new Object Methods Methods can be added using any object creation mechanism Example function person(firstname, lastname, age) { this.firstname = firstname; this.lastname = lastname; this.age = age; this.eyecolor = eyecolor; this.getfullname = function () { return this.firstname + " " + this.lastname; } }

Function Parameters and Arguments Functions can have parameters functionname(param1, param2, para3) { } code to be executed Function parameters are the names listed in the function definition Function arguments are the real values passed to (and received by) the function

Parameter Rules JavaScript function definitions do not specify data types for parameters JavaScript functions do not perform type checking on the passed arguments (see Rule 1) JavaScript functions do not check the number of arguments received

Parameter Defaults If a function is called with missing arguments (less than declared), the missing values are set to: undefined You may want to assign a default value to the parameter function myfunction(x, y) { } if (y === undefined) { } y = 0; If a function is called with too many arguments (more than declared), they will not have a name, and can only be reached in the arguments object.

The Arguments Object JavaScript functions have a built-in object called the arguments object The argument object contains an array of the arguments used when the function was called (invoked)

The Arguments Object Example function findmax() { var i, max = Number.MIN_VALUE; for (i = 0; i < arguments.length; i++) { if (arguments[i] > max) { max = arguments[i]; } } return max; } x = findmax(1, 123, 500, 115, 44, 88);

JavaScript Arrays An array is a variable that can hold multiple values Syntax var buildings = ["Beury", "SERC", "Tuttleman"] Allows you to loop through a list of values to perform various operations Individual values are accessed using an index number

JavaScript Arrays Think of an array as a special type of object that uses numbers to access its elements instead of property names The first element is stored at index 0, the second element at index 1, etc. mycars[0] = "Accord"; alert(mycars[1]); You can have different objects in one array myarray[0] = Date.now; myarray[1] = myfunction; myarray[2] = mycars;

Array Properties and Methods Array objects have various properties and methods var x = myarray.length; // The length property returns the number of elements var y = myarray.sort(); // returns a sorted copy

Array Properties and Methods Property constructor length prototype Description Returns the function that created the Array object's prototype Sets or returns the number of elements in an array Allows you to add properties and methods to an Array object

Array Properties and Methods Method concat() indexof() join() lastindexof() pop() push() reverse() shift() slice() sort() splice() tostring() unshift() valueof() Description Joins two or more arrays, and returns a copy of the joined arrays Search the array for an element and returns its position Joins all elements of an array into a string Search the array for an element, starting at the end, and returns its position Removes the last element of an array, and returns that element Adds new elements to the end of an array, and returns the new length Reverses the order of the elements in an array Removes the first element of an array, and returns that element Selects a part of an array, and returns the new array Sorts the elements of an array Adds/Removes elements from an array Converts an array to a string, and returns the result Adds new elements to the beginning of an array, and returns the new length Returns the primitive value of an array

Looping through an Array var buildings = ["Beury", "SERC", "Tuttleman", "Wachman"]; for (var i = 0; index < buildings.length; i++) { } text += " " + buildings[i];

Use Array Literal Avoid using the new Keyword when creating Arrays as this creates complications var points = new Array(40, 100); Creates an array with two elements (40 and 100) var points = new Array(40); Creates an array with 40 undefined elements