JavaScript Miscellany - Advance Java Web Technology - Lecture Slides, Slides of Computer Science

These are the Lecture Slides of Advance Java Web Technology which includes Hypertext Transfer Protocol, HTTP Messages, Web Servers, Body of Message, Header Section, HTTP Command, HTTP Version Number, Document Address, Used for Debugging etc. Key important points are: Javascript Miscellany, Properties of Functions, Formal Parameters, Constructor Functions, Prototype, Array of Actual Parameters, Kind of Loop, Global and Local Variables, Function Methods

Typology: Slides

2012/2013

Uploaded on 03/19/2013

dharamnishth
dharamnishth 🇮🇳

2.5

(2)

50 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
JavaScript Miscellany
Docsity.com
pf3
pf4
pf5

Partial preview of the text

Download JavaScript Miscellany - Advance Java Web Technology - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

JavaScript Miscellany

Properties of functions

  • Functions are objects, and have properties
    • length – the number of formal parameters
    • arguments – the Arguments object, which is “like” an array of actual parameters - Note: length is not necessarily equal to arguments.length
    • caller – the function that invoked this one, or null if the function was invoked from the top level
    • prototype (for constructor functions) – an object that defines properties and methods of functions created with this constructor

Global and local variables

  • A variable is local to a function if
    • It is a formal parameter of the function
    • It is declared with var inside the function (e.g. var x = 5 )
  • Otherwise, variables are global
  • Specifically, a variable is global if
    • It is declared outside any function (with or without var)
    • It is declared by assignment inside a function (e.g. x = 5 )

Methods I

  • First we construct an object:
    • function Point(xcoord, ycoord) { this.x = xcoord; // keyword "this" is mandatory this.y = ycoord; }
    • myPoint = new Point(3, 5);
  • A method is a function that is associated with, and

invoked through, an object (hence can use this)

  • Here is a “function” that makes no sense by itself:
    • function distance(x2, y2) { function sqr(x) { return x * x; } return Math.sqrt(sqr(this.x – x2) + sqr(this.y – y2)); }

The End