DOC PREVIEW
Penn CIT 597 - More JavaScript

This preview shows page 1-2-14-15-30-31 out of 31 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

More JavaScriptBrowser supportWhat you can’t doDebuggingNumbersStrings and charactersSome string methodsMore string methodsbooleanundefined and nullArraysDetermining typesWrappers and conversionsVariablesHTML names in JavaScriptMore about withFunctionsThe Function() constructorFunction literalsFunction namesThe call objectargumentsExample uses of argumentsProperties of functions IProperties of functions IIGlobal and local variablesFunctions and methodsMethods IMethods IIMethods IIIThe EndJan 14, 2019More JavaScript2Browser supportJavaScript works on almost all browsersInternet Explorer uses JScript (referred to in menus as “Active Scripting”), which is Microsoft’s dialect of JavaScriptOlder browsers don’t support some of the newer features of JavaScriptWe will assume modern browser supportEnabling and disabling JavaScript:See http://www.valleyvet.com/si_javascript_help.html3What you can’t doTo protect the visitor to your web pages, you can’t:Read or write user filesHowever, JScript on IE allows ASP scripting, which is how the very destructive JS.Gigger.A@mm worm spreadsTo turn off active scripting in Outlook Express, seehttp://support.microsoft.com/support/kb/articles/Q192/8/46.ASPExecute any other programsConnect to any other computer, except to download another HTML page or to send e-mailDetermine what other sites the user has visitedOpen a very small (less than 100px by 100px) window or an offscreen window (except in IE)4DebuggingMozilla/Netscape has much better debugging tools than IEMozillaSelect Tools => Web Development => JavaScript consoleNetscape 6:Select Tasks => Tools => JavaScript consoleNetscape 4:Select Communicator => Tools => JavaScript consoleAny Mozilla or Netscape:Type javascript: in the location bar and press EnterInternet Explorer:Go to the Preferences... dialog and look for something like Web content => Show scripting error alertsAfter debugging, test your program in IEIE is the most popular browser5NumbersIn JavaScript, all numbers are floating pointSpecial predefined numbers:Infinity, Number.POSITIVE_INFINITY -- the result of dividing a positive number by zeroNumber.NEGATIVE_INFINITY -- the result of dividing a negative number by zeroNaN, Number.NaN (Not a Number) -- the result of dividing 0/0NaN is unequal to everything, even itselfThere is a global isNaN() functionNumber.MAX_VALUE -- the largest representable numberNumber.MIN_VALUE -- the smallest (closest to zero) representable number6Strings and charactersIn JavaScript, string is a primitive typeStrings are surrounded by either single quotes or double quotesThere is no “character” typeSpecial characters are:\0 NUL\b backspace\f form feed\n newline\r carriage return\t horizontal tab\v vertical tab\' single quote\" double quote\\ backslash\xDD Unicode hex DD\xDDDD Unicode hex DDDD7Some string methodscharAt(n)Returns the n th character of a stringconcat(string1, ..., stringN)Concatenates the string arguments to the recipient stringindexOf(substring)Returns the position of the first character of substring in the recipient string, or -1 if not foundindexOf(substring, start)Returns the position of the first character of substring in the given string that begins at or after position start, or -1 if not foundlastIndexOf(substring), lastIndexOf(substring, start)Like indexOf, but searching starts from the end of the recipient string8More string methodsmatch(regexp )Returns an array containing the results, or null if no match is foundOn a successful match:If g (global) is set, the array contains the matched substringsIf g is not set:Array location 0 contains the matched textLocations 1... contain text matched by parenthesized groupsThe array index property gives the first matched positionreplace(regexp, repl ac e ment)Returns a new string that has the matched substring replaced with the replaceme ntsearch(regexp)Returns the position of the first matched substring in the given string, or -1 if not found.9booleanThe boolean values are true and falseWhen converted to a boolean, the following values are also false:0"0" and '0'The empty string, '' or ""undefinednullNaN10undefined and nullThere are special values undefined and nullundefined is the only value of its “type”This is the value of a variable that has been declared but not defined, or an object property that does not existvoid is an operator that, applied to any value, returns the value undefinednull is an “object” with no propertiesnull and undefined are == but not ===11ArraysAs in C and Java, there are no “true” multidimensional arraysHowever, an array can contain arraysThe syntax for array reference is as in C and JavaExample: var a = [ ["red", 255], ["green", 128] ]; var b = a[1][0]; // b is now "green" var c = a[1]; // c is now ["green", 128] var d = c[1]; // d is now 12812Determining typesThe unary operator typeof returns one of the following strings: "number", "string", "boolean", "object", "undefined", and "function"typeof null is "object"If myArray is an array, typeof myArray is "object"To distinguish between different types of objects,myObje ct instanceof ConstructorThe Constructor should be an object that is a constructor functionIt is an error if the right-hand side is not an object at allmyObje ct.constructor == ConstructormyObje ct.toString() == "ConstructorName"13Wrappers and conversionsJavaScript has “wrapper” objects for when a primitive value must be treated as an objectvar s = new String("Hello"); // s is now a Stringvar n = new Number(5); // n is now a Numbervar b = new Boolean(true); // b is now a BooleanBecause JavaScript does automatic conversions as needed, wrapper objects are hardly ever neededJavaScript has no “casts,” but conversions can be forcedvar s = x + ""; // s is now a stringvar n = x - 0; // n is now a numbervar b = !!x; // b is now a booleanBecause JavaScript does automatic conversions as needed, explicit conversions are hardly ever needed14VariablesEvery variable is a property of an objectWhen JavaScript starts, it creates a global objectIn client-side JavaScript, the window is the global objectIt can be referred to as window or as thisThe


View Full Document

Penn CIT 597 - More JavaScript

Documents in this Course
DOM

DOM

21 pages

More DOM

More DOM

11 pages

Rails

Rails

33 pages

DOM

DOM

21 pages

RELAX NG

RELAX NG

31 pages

RELAX NG

RELAX NG

31 pages

RELAX NG

RELAX NG

31 pages

RELAX NG

RELAX NG

31 pages

Rake

Rake

12 pages

Ruby

Ruby

58 pages

DOM

DOM

21 pages

Tomcat

Tomcat

16 pages

DOM

DOM

21 pages

Servlets

Servlets

29 pages

Logging

Logging

17 pages

Html

Html

27 pages

DOM

DOM

22 pages

RELAX NG

RELAX NG

30 pages

Servlets

Servlets

28 pages

XHTML

XHTML

13 pages

DOM

DOM

21 pages

DOM

DOM

21 pages

Servlets

Servlets

26 pages

More CSS

More CSS

18 pages

Servlets

Servlets

29 pages

Logging

Logging

17 pages

Load more
Download More JavaScript
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view More JavaScript and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view More JavaScript 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?