JavaScript 2. Jef De Smedt Beta VZW
|
|
- Dorthy Crawford
- 5 years ago
- Views:
Transcription
1 JavaScript 2 Jef De Smedt Beta VZW
2 Overview Introduction Basic elements of JavaScript Arrays Window object Document Object Model Forms Events Objects
3 Recap JavaScript is a scripting language that is browser specific EcmaScript is a standard language which only describes the language, not how to access the elements in the browser JavaScript can access the browser using the window-object Window is the default object in a browser We can access the HTML page with window.document (or, since window is default, just document) The document object uses the Document Object Model (DOM)
4 Recap: the document object Access the HTML elements in JavaScript => Document Object Model (DOM) <html><head></head><body><ol><li>one</li><li>two</li></ol></body></html> html head Child element Parent element body ol li one Text element li one The DOM-tree
5 Recap: the text of an element <!DOCTYPE html> <html> <head> <title>copy values</title> </head> <body> <h1 id="heading">title</h1> <div id="body"></div> <script> var elh1 = document.getelementbyid("heading"); var elbody = document.getelementbyid("body"); elbody.textcontent = elh1.textcontent; </script> </body> </html>
6 Recap: the value attribute (some) Elements have textnode children The text of an <input>-element is not a textnode <input type= text id= name name= name value= John /> <!DOCTYPE html> <html> <head> <title>value attribute</title> </head> <body> <h1 id="heading">john</h1> <input type="text" id="name" name="name" value="nobody"/> <script> var elh1 = document.getelementbyid("heading"); var elname = document.getelementbyid("name"); elname.value = elh1.textcontent; </script> </body> </html> Quite often attributes can be accessed as properties A more generic way is using setattribute and getattribute. elname.setattribute("value", elh1.textcontent);
7 Recap: Clicking on a button <!DOCTYPE html> <html> <head> <title>onclick attribute</title> <script> function SayHi() { </script> </head> <body> alert("hi all"); <h1 id="heading">john</h1> <button id="btn2" onclick="sayhi();">say hi</button> </body> </html> A function is executed when it is called, not when it is read by the browser JavaScript code to execute the function.
8 Recap: Onclick property vs Onclick attribute Instead of using the HTML onclick attribute we can also use the JavaScript onclick property (compare to: HTML value attribute and JavaScript value property) <body> <form> Name: <input type="text" id="txtname"/> <input id="btn" type="button" value="say hi"/> <div id="result"></div> <script> var btn = document.getelementbyid("btn"); btn.onclick = SayHi; </script> </form> </body>
9 Exercise edit Edit field with button. There is also a div below the edit field When the user enters a name and clicks on the button A greeting should appear. The greeting is time dependent: Before 13:00: good morning 13:00 and later: good afternoon
10 Exercise Select 2 select elements, 2 buttons and a list with names When an element is selected and you click on the button > the selected element is moved from left to right Of course this should also work for the toleft button. Extra: when no item is selected, the corresponding button should be disabled
11 Why use btn.onclick instead of < onclick= >? We want to separate the JavaScript code from the HTML code Compare to styles: in most cases you should not use the style attribute in HTML Clear separation between HTML and JavaScript is one of the principles of unobtrusive JavaScript: the site should still work without JavaScript Let us look at an example
12 The obtrusive way This will not work if JavaScript is disabled and there is no way to make it work: <a href="javascript:window.open(' _principles_of_unobtrusive_javascript')">w3c Article</a> The following will work if JavaScript is disabled but it is a maintenance nightmare <a href=" ve_javascript" onclick="window.open(' les_of_unobtrusive_javascript');return false;">w3c Article</a>
13 The unobtrusive way <a class="newwindow" href=" pt">w3c Article</a> <script> var anchors = document.getelementsbyclassname("newwindow"); for (var i=0; i<anchors.length;i++) { anchors[i].onclick = OpenWindow; function OpenWindow(){ window.open(this.href); return false; </script> return false: Do not execute the default behavior (=follow link) The keyword this refers to the <a>-element
14 HTML Forms and JavaScript JavaScript can be used to check form input We need a way to check the fields (HTML5 has many ways to check input, we will use the JavaScript approach here) We need a way to prevent submitting the form We need a way to show an error We can check fields by finding them in the DOM-tree We can prevent submitting a form by having a function return false (prevents default action) We can show an error by changing the css-class of an element
15 Finding elements When we have a class required <form method="get" action=" id="bingform"> <label for="q">search</label> <input type="text" name="q" id="q" class="required"/> <input type="submit" value="submit"/> </form> we can find all the required child elements of a form using getelementsbyclassname: form.getelementsbyclassname( required );
16 Prevent submitting a form The default action for a form is submitting When an eventhandler returns false, the default action will not be executed var f=document.getelementbyid("bingform"); f.onsubmit = checkrequired; function checkrequired() { if (checks_are_ok){ return true; else{ return false;
17 Combined with getelementsbyclassname function checkrequired() { var requiredelements = this.getelementsbyclassname("required"); for (var i=0;i<requiredelements.length;i++) { var val = requiredelements[i].value; if (val === null val.trim() === "") { return false; return true; Because checkrequired is added to the form, this refers to the form.
18 Show error by changing css-class <style>.hideerror{ display:none;.showerror{ display:inline; color: red; </style> We have to change the class from hideerror to showerror in case of an error <form method="get" action=" id="bingform"> <div> <label for="q">search</label> <input type="text" name="q" id="q" class="required"/> <span class="hideerror">field is required</span> </div> <input type="submit" value="submit"/> </form>
19 Show error by changing css-class Most HTML-attributes are accessible as JavaScript properties (value, href, ) However class is a reserved word in JavaScript =>.classname element.classname = showerror ; But how do we find the span-element? requiredelements[i].nextelementsibling.classname= showerror ; nextelementsibling returns the next element with the same parent. (nextsibling would return the next node with the same parent => textnode.)
20 What if there is more than one class.classname is a space separated list of classnames element.classname overwrites the existing css-classes In this example that is OK (we want to change hideerror into showerror ) In modern browsers we can use classlist: var error = requiredelements[i].nextelementsibling; if (val === null val.trim() === "") { error.classlist.remove("hideerror"); error.classlist.add("showerror"); return false;
21 Altering a form before submitting When we want to search Bing.com for videos, we have to change the URL: Let us try searching in videos using a checkbox We do not add a name because we do not want to send the checkbox to Bing <div> <label><input type="checkbox" id="invideos"/>search in videos</label> </div>
22 Altering a form before submitting We can change the HTML action attribute by changing the.action property in JavaScript var invideo = document.getelementbyid("invideos"); if (invideo.checked){ this.action += "/videos"; Refers to the form
23 Anonymous functions When a function is used in only one place, we do not really have to give it a name => anonymous function f.onsubmit = function() { var requiredelements = this.getelementsbyclassname("required"); for (var i=0;i<requiredelements.length;i++) { var val = requiredelements[i].value; if (val === null val.trim() === "") { return false;
24 Searching google Because there are no French websites in the Netherlands, this combination should give an error Every other combination should be OK Possible values: languages(all, French, Dutch), countries(all, France, Belgium, Netherlands)
25 Summary: finding elements document.getelementbyid( id ): returns one element document.getelementsbytagname( input ): returns all input elements in a document element.getelementsbyclassname( class ): returns a collection of all element children with a certain class form.elements.nameditem( name_or_id ): returns an element with name or id (IE: no name) in a form
26 Advanced events The onclick, onsubmit, on events are one way to work with events There is also the addeventlistener function Disadvantage Does not work in older versions of IE (<9) and Opera (<7): attachevent Advantages Can also add eventhandlers to textnodes, the window object, XMLHttpRequest object, Can add multiple handlers for the same event Can also react to event capturing
27 Capturing and bubbling <!DOCTYPE html> <html> <head> </head> Div is a child of body(in z- <body id="body"> order body sits behind div) <div id="div"> Paragraph is a child of div (div sits behind paragraph) <p id="paragraph">text</p> </div> </body> </html>
28 Capturing and bubbling <script> var body = document.getelementbyid("body"); var para = document.getelementbyid("paragraph"); var div = document.getelementbyid("div"); body.addeventlistener("click", function() { alert("body is clicked(bubbling)"); ); body.addeventlistener("click", function() { alert("body is clicked(capturing)");, true); para.addeventlistener("click", function() { alert("paragraph is clicked(capturing)");, true); para.addeventlistener("click", function(){ alert("paragraph is clicked(bubbling)"); ); div.addeventlistener("click", function(){ alert("div is clicked(bubbling)"); ); div.addeventlistener("click", function() { alert("div is clicked(capturing)");, true); </script> Adds capturing and bubbling eventhandlers to body, div and paragraph. Order of alerts: 1. Body is clicked (capturing) 2. Div is clicked(capturing) 3. Paragraph is clicked(capturing) 4. Paragraph is clicked(bubbling) 5. Div is clicked(bubbling) 6. Body is clicked(bubbling) usecapture parameter (default is false)
29 Capturing and bubbling (more general) <script> var body = document.getelementbyid("body"); var para = document.getelementbyid("paragraph"); var div = document.getelementbyid("div"); body.addeventlistener("click", showclick); function showclick(event){ var element = this.localname; var phase = ""; switch(event.eventphase) { case event.capturing_phase: phase="capturing"; break; case event.bubbling_phase: phase="bubbling"; break; case event.at_target: phase="at target"; break; alert("element: "+element + " in phase: "+phase); </script> Function is owned by body, div or para => this Paragraph is at target (no capture or bubble)
30 AddEventListener remarks We can also remove event listeners: removeeventlistener In IE 8 en Opera 6: attachevent Possible cross browser solution: if (x.addeventlistener) { x.addeventlistener("click", myfunction); else if (x.attachevent) { x.attachevent("onclick", myfunction); IE 8: no event argument => window.event
31 Window.onload vs DOMContentLoaded Up till now we put our script at the end of the DOM-tree => DOM tree is loaded We can also use an event to execute a JavaScript function when the page is loaded: onload-event This event also exists for the window object Because the window object always exists we can put our script in the <head> element The onload event happens when the page is completely loaded (DOM-tree, images, styles, )
32 Window.onload vs DOMContentLoaded <!DOCTYPE html> <html> <head> <title>onload event</title> <script> "use strict"; window.onload = function(){ var para = document.getelementbyid("para"); para.innerhtml="i can write JavaScript"; </script> </head> <body> <p id="para"></p> </body> </html>
33 Window.onload vs DOMContentLoaded DOMContentLoaded event occurs when the DOM-tree is fully loaded It comes before window.onload => JavaScript code will run sooner It is defined on the document object
34 Window.onload vs DOMContentLoaded <!DOCTYPE html> <html> <head> <title>onload event</title> <script> "use strict"; document.addeventlistener("domcontentloaded", function(){ var para = document.getelementbyid("para"); para.innerhtml="i am first"; ); </script> </head> <body> <p id="para"></p> </body> </html>
35 Object oriented JavaScript JavaScript is not an object oriented programming language like Java, C++, C#, Objective C, Python, Ruby, PHP, ) JavaScript has no classes but uses prototypes JavaScript makes no difference between objects and namespaces
36 JavaScript namespaces Let us assume we want to create a library in JavaScript that can be used to do mathematical calculations: "use strict"; var PI= ; function CircleCircumference(radius){ return 2 * PI * radius; function CircleArea(radius) { return PI * radius * radius;
37 JavaScript namespaces We can use this library in an HTML page: <!DOCTYPE html> <html> <head> <title>namespaces</title> <script src="mathlib.js"></script> <script> "use strict"; document.addeventlistener("domcontentloaded", function() { var radius = 3; var circumference = CircleCircumference(radius); document.write("a circle with radius " + radius + " has circumference " + circumference); ); </script> </head> <body> </body> </html>
38 JavaScript namespaces This works and gives the result: A circle with radius 3 has circumference However when we add one line: <html> <head> <title>namespaces</title> <script src="mathlib.js"></script> <script src="movielib.js"></script> <script> We get this result: A circle with radius 3 has circumference NaN
39 JavaScript namespaces This is because of the contents of movielib.js: "use strict"; var PI = "Irrfan Khan"; This statement overwrites the value of PI We can create the variable in a namespace MyMovie "use strict"; var MyMovie = {PI:"Irrfan Khan";
40 JavaScript namespaces We can do the same thing for the Math variable "use strict"; var MyMath = {PI: ; function CircleCircumference(radius){ return 2 * MyMath.PI * radius; To refer to PI in the MyMath namespace we use the dot notation.
41 JavaScript objects We define an object in the same way: var p1 = {FirstName:John, LastName:Lennon; var p2 = {FirstName:George, LastName:Martin; We could say that p1 and p2 are persons but there is no such thing as a Person class => not all person-object will have the same properties
42 Factory method Using a factory method we can create objects with the same properties easier function personfactory(firstname, lastname){ var p = {Firstname: firstname, Lastname: lastname; return p; var person = personfactory( John, Lennon ); This is what the new operator does
43 JavaScript constructor with new operator We can make objects uniform by using a function: function Person(firstname, lastname){ this.firstname = firstname; this.lastname = lastname; var p1 = new Person( John, Lennon ); document.write(p1.firstname); // John Using the new-operator we create a new object Next the function Person is called This refers to the newly created object => every object created using the Person function has a FirstName and a LastName
44 JavaScript object methods Every person object gets its own FirstName and LastName When we look at the object p1 (console.dir) we see the following: The special property proto is copied from the prototype property of the Person function. It is shared by all objects that are instantiated by new Person() When we use the dot operator the JavaScript engine looks for the item on the object itself. If it is not found, it will look for the item in proto
45 JavaScript object methods We can add a function to the prototype property of Person: Person.prototype.GetFullName = function() { return this.firstname + " " + this.lastname; This method is now available for all Person-objects (new Person()) When we write var name= p1.getfullname(); The engine will first look for the function on the object itself. If it is not found it will look for the function in proto
46 Ecmascript 6 (not in Internet Explorer):class The class keyword does exactly the same thing class Person{ constructor(firstname, lastname){ this.firstname = firstname; this.lastname = lastname; GetFullname(){ return this.firstname + " " + this.lastname; let p = new Person("John", "Lennon"); console.log(p.getfullname());
47 What does new do? 1. It creates a new Object 2. It copies the prototype of the constructor function to the new Object 3. It invokes the constructor function on the object together with the arguments
48 What does new do? function Person(firstname, lastname){ this.firstname = firstname; this.lastname = lastname; var p = new Person("John", "Doe"); console.log(p.firstname); This is the same as this function Person(firstname, lastname){ this.firstname = firstname; this.lastname = lastname; var p2 = Object.create(Person.prototype); Person.apply(p2, ["Mary", "Doe"]); console.log(p2.firstname); p2 becomes this in the Person function
49 JavaScript object methods this in GetFullName() refers to the namespace/object in which the function is executed = > p1 When we execute console.dir(p1) we see the following: If we were to add GetFullName() to p1 (p1.getfullname= ) that would take precedence over proto.getfullname (prototypical inheritance)
50 The JavaScript function object Every function is an object and has a prototype The prototype has a call() function to use the function with an object (which we will never do) function GetFullName2(){ return this.firstname + " " + this.lastname; document.write(getfullname2.call(p1) + "<br>"); By calling call(p1) we set p1 as the this object.
51 Closures JavaScript has two variable scopes: global and (function) local Global or window scope (name is available everywhere in the script): var name="john"; Every variable declared in a function is only available in the function: function DoSomething() { var number = 42; JavaScript does not have block scope when we use var while(i<10){ var j = 5; i++; document.write(j); J is known outside of block. If this while-statement is used at the top-level (global) scope, j becomes part of the window object.
52 Intermezzo: remember hoisting The code while(i<10){ var j = 5; i++; Is the same as var j; while(i<10){ j = 5; i++; Conclusion: variables are hoisted on the global and function level
53 Closures The lifetime of a function scoped variable is equal to the execution time of the function: function DoSomething(){ var i; document.write(i); DoSomething(); Variable i exists only during the execution of this statement.
54 Intermezzo: inner functions In JavaScript functions can be nested A nested function has access to the local variables of its parent function function outerfunction() { var i=42; function innerfunction() { document.write(i); variable i is accessible in the inner function
55 Closures Closure defines a local variable with a lifetime that exceeds the execution time of the function When a variable in a parent function is used in an inner function, the variable remains available to the inner function even after the parent function has finished executing But maybe we better take a look at an example
56 Closures <script> "use strict"; var add = function(){ var counter=0; return function() { counter++; (); add(); add(); </script> document.write(counter + "<br>"); Mind the call-operator, Richard! (minding the call operator, dear) The variable add is not equal to the anonymous function, but to the returnvalue of this function. The returnvalue is also a function. This inner function refers to counter which is defined in the outer function. Every time we call add(), we are in fact calling the inner function. The variable counter is initialized once (during the execution of the parent function). The variable will remain accessible to the inner function. Output: 1 2
57 Closure in an object oriented way(module design pattern) obj has a private member variable (state) We can get the value using GetCounter() We can change the value using Increment() var obj = function() { var counter = 0; return { GetCounter: function() {return counter;, Increment: function() {counter++; (); obj.increment(); document.write(obj.getcounter());
58 Be carefull with closures In the next example all invocations of the id() function will return 3 function uniqueidcreator(people){ var ID=1; for (var i=0;i<people.length;i++){ people[i]["id"] = function(){ return ID + i; return people; var people = [{name:"john",id:0, {name:"paul", id:0]; var peoplewithid = uniqueidcreator(people); for(var i=0;i<people.length;i++){ console.log(people[i].name + ": " + people[i].id());
59 Solution: immediately invoked functions The next example returns the right result function uniqueidcreator(people){ var ID=1; for (var i=0;i<people.length;i++){ people[i]["id"] = function(j){ return function(){ return ID + j; (i);//immediately invoking the function return people; var people = [{name:"john",id:0, {name:"paul", id:0]; var peoplewithid = uniqueidcreator(people); for(var i=0;i<people.length;i++){ console.log(people[i].name + ": " + people[i].id());
60 Let to the rescue!!! function uniqueidcreator(people){ var ID=1; for (let i=0;i<people.length;i++){ people[i]["id"] = function(){ return ID + i; return people; var people = [{name:"john",id:0, {name:"paul", id:0]; var peoplewithid = uniqueidcreator(people); for(var i=0;i<people.length;i++){ console.log(people[i].name + ": " + people[i].id()); Let will create a new scope for each iteration, effectively creating an unique value that will not change afterwards.
61 TypeScript A better JavaScript
62 Purpose JavaScript was originally intended to be a scripting language for simple tasks It is difficult to write big programs in such a language This gave rise to alternatives: Coffeescript, Dart, TypeScript TypeScript differs from the other two in that a normal JavaScript program also is a valid TypeScript program.
63 Typed variables let isdone: boolean = false; let decimal: number = 6; let color: string = "blue"; let list: number[] = [1, 2, 3]; enum Color {Red, Green, Blue let c: Color = Color.Green; let notsure: any = 4; function warnuser(): void { alert("this is my warning message"); In Typescript we can define the type of a variable. The Typescript compiler will check the type. Important: when you have an error in your types, the compiler will still emit JavaScript code. let somevalue: any = "this is a string"; let strlength: number = (<string>somevalue).length; //Type assertions (casting)
64 Functions Named function Argument type function add(x: number, y: number): number { return x + y; Anonymous function Return type let myadd = function(x: number, y: number): number { return x + y; ; Functions are also typed in typescript. For each of the arguments we define the type and we also add the returntype
65 Generics function identity<t>(arg: T): T { return arg; let output = identity<string>("mystring"); When we have a typed language like TypeScript, it is useful to have generics. In this example the variable output will be of type string
66 Interfaces: Duck typing If it walks like a duck and quacks like a duck, it is a duck We don t implement an interface. Typescript checks whether all elements of the interface are available interface LabelledValue { label: string; A LabelledValue is an Object that has a label function printlabel(labelledobj: LabelledValue) { console.log(labelledobj.label); let myobj = {size: 10, label: "Size 10 Object"; printlabel(myobj); myobj has a label, so we can use it with printlabel printlabel takes an argument of type LabelledValye
67 Classes class Greeter { greeting: string; constructor(message: string) { this.greeting = message; greet() { return "Hello, " + this.greeting; let greeter = new Greeter("world"); console.log(greeter.greet()); A class has a constructor function that will be used to initialise the object. It is transpiled into the following JavaScript code. "use strict"; var Greeter = */ (function () { function Greeter(message) { this.greeting = message; Greeter.prototype.greet = function () { return "Hello, " + this.greeting; ; return Greeter; ()); var greeter = new Greeter("world"); console.log(greeter.greet());
68 Inheritance class Animal { move(distanceinmeters: number = 0) { console.log(`animal moved ${distanceinmetersm.`); class Dog extends Animal { bark() { console.log('woof! Woof!'); Formatted string When a class extends another class it inherits the methods of the base class. const dog = new Dog(); dog.bark(); dog.move(10); dog.bark();
JavaScript. Jef De Smedt Beta VZW
JavaScript Jef De Smedt Beta VZW Getting to know Beta VZW: Association founded in 1993 Computer courses for the unemployed and for employees www.betavzw.org(dutch) Cevora VZW/Cefora ASBL 09:00u-12:30u
More informationSolutions to exercises
Solutions to exercises Exercise textbox greetings Name: var button = document.getelementbyid("button");
More informationTypeScript. Types. CS144: Web Applications
TypeScript Superset of JavaScript (a.k.a. JavaScript++) to make it easier to program for largescale JavaScript projects New features: types, interfaces, decorators,... All additional TypeScript features
More informationCISC 1600 Lecture 2.4 Introduction to JavaScript
CISC 1600 Lecture 2.4 Introduction to JavaScript Topics: Javascript overview The DOM Variables and objects Selection and Repetition Functions A simple animation What is JavaScript? JavaScript is not Java
More informationINLEDANDE WEBBPROGRAMMERING MED JAVASCRIPT INTRODUCTION TO WEB PROGRAMING USING JAVASCRIPT
INLEDANDE WEBBPROGRAMMERING MED JAVASCRIPT INTRODUCTION TO WEB PROGRAMING USING JAVASCRIPT ME152A L4: 1. HIGHER ORDER FUNCTIONS 2. REGULAR EXPRESSIONS 3. JAVASCRIPT - HTML 4. DOM AND EVENTS OUTLINE What
More informationJavascript. Many examples from Kyle Simpson: Scope and Closures
Javascript Many examples from Kyle Simpson: Scope and Closures What is JavaScript? Not related to Java (except that syntax is C/Java- like) Created by Brendan Eich at Netscape later standardized through
More informationCSC Javascript
CSC 4800 Javascript See book! Javascript Syntax How to embed javascript between from an external file In an event handler URL - bookmarklet
More informationJavaScript or: How I Learned to Stop Worrying and Love a Classless Loosely Typed Language
JavaScript or: How I Learned to Stop Worrying and Love a Classless Loosely Typed Language Part 1 JavaScript the language What is JavaScript? Why do people hate JavaScript? / Should *you* hate JavaScript?
More informationFALL 2017 CS 498RK JAVASCRIPT. Fashionable and Functional!
CS 498RK FALL 2017 JAVASCRIPT Fashionable and Functional! JAVASCRIPT popular scripting language on the Web, supported by browsers separate scripting from structure (HTML) and presentation (CSS) client-
More informationClient vs Server Scripting
Client vs Server Scripting PHP is a server side scripting method. Why might server side scripting not be a good idea? What is a solution? We could try having the user download scripts that run on their
More informationJavaScript s role on the Web
Chris Panayiotou JavaScript s role on the Web JavaScript Programming Language Developed by Netscape for use in Navigator Web Browsers Purpose make web pages (documents) more dynamic and interactive Change
More informationCSI 3140 WWW Structures, Techniques and Standards. Browsers and the DOM
CSI 3140 WWW Structures, Techniques and Standards Browsers and the DOM Overview The Document Object Model (DOM) is an API that allows programs to interact with HTML (or XML) documents In typical browsers,
More informationOne language to rule them all: TypeScript. Gil Fink CEO and Senior Consultant, sparxys
One language to rule them all: TypeScript Gil Fink CEO and Senior Consultant, sparxys About Me sparxys CEO and Senior consultant Microsoft MVP in the last 8 years Pro Single Page Application Development
More informationJavaScript Introduction
JavaScript Introduction Web Technologies I. Zsolt Tóth University of Miskolc 2016 Zsolt Tóth (UM) JavaScript Introduction 2016 1 / 31 Introduction Table of Contents 1 Introduction 2 Syntax Variables Control
More informationJavaScript for C# Programmers Kevin
JavaScript for C# Programmers Kevin Jones kevin@rocksolidknowledge.com @kevinrjones http://www.github.com/kevinrjones Agenda Types Basic Syntax Objects Functions 2 Basics 'C' like language braces brackets
More informationJavaScript. What s wrong with JavaScript?
JavaScript 1 What s wrong with JavaScript? A very powerful language, yet Often hated Browser inconsistencies Misunderstood Developers find it painful Lagging tool support Bad name for a language! Java
More informationNotes on JavaScript (aka ECMAScript) and the DOM
Notes on JavaScript (aka ECMAScript) and the DOM JavaScript highlights: Syntax and control structures superficially resemble Java/C/C++ Dynamically typed Has primitive types and strings (which behave more
More informationNode.js Training JavaScript. Richard richardrodger.com
Node.js Training JavaScript Richard Rodger @rjrodger richardrodger.com richard.rodger@nearform.com A New Look at JavaScript Embracing JavaScript JavaScript Data Structures JavaScript Functions Functional
More informationJavaScript: Sort of a Big Deal,
: Sort of a Big Deal, But Sort of Quirky... March 20, 2017 Lisp in C s Clothing (Crockford, 2001) Dynamically Typed: no static type annotations or type checks. C-Like Syntax: curly-braces, for, semicolons,
More informationInteractor Tree. Edith Law & Mike Terry
Interactor Tree Edith Law & Mike Terry Today s YouTube Break https://www.youtube.com/watch?v=mqqo-iog4qw Routing Events to Widgets Say I click on the CS349 button, which produces a mouse event that is
More information5. Strict mode use strict ; 6. Statement without semicolon, with semicolon 7. Keywords 8. Variables var keyword and global scope variable 9.
Javascript 1) Javascript Implementation 1. The Core(ECMAScript) 2. DOM 3. BOM 2) ECMAScript describes 1. Syntax 2. Types 3. Statements 4. Keywords 5. Reserved words 6. Operators 7. Objects 3) DOM 1. Tree
More informationThe course is supplemented by numerous hands-on labs that help attendees reinforce their theoretical knowledge of the learned material.
Lincoln Land Community College Capital City Training Center 130 West Mason Springfield, IL 62702 217-782-7436 www.llcc.edu/cctc WA2442 Introduction to JavaScript Objectives This intensive training course
More informationJavaScript or: HOW I LEARNED TO STOP WORRYING AND LOVE A CLASSLESS*
JavaScript or: HOW I LEARNED TO STOP WORRYING AND LOVE A CLASSLESS* LOOSELY TYPED LANGUAGE Two parts Part 1 JavaScript the language Part 2 What is it good for? Part 1 JavaScript the language What is JavaScript?
More informationWeb Site Development with HTML/JavaScrip
Hands-On Web Site Development with HTML/JavaScrip Course Description This Hands-On Web programming course provides a thorough introduction to implementing a full-featured Web site on the Internet or corporate
More informationXML JavaScript Object Notation JSON Cookies Miscellaneous What Javascript can t do. OOP Concepts of JS
LECTURE-4 XML JavaScript Object Notation JSON Cookies Miscellaneous What Javascript can t do. OOP Concepts of JS 1 XML EXTENDED MARKUP LANGUAGE XML is a markup language, like HTML Designed to carry data
More informationWeb Programming and Design. MPT Junior Cycle Tutor: Tamara Demonstrators: Aaron, Marion, Hugh
Web Programming and Design MPT Junior Cycle Tutor: Tamara Demonstrators: Aaron, Marion, Hugh Plan for the next 5 weeks: Introduction to HTML tags, creating our template file Introduction to CSS and style
More informationThis course is designed for web developers that want to learn HTML5, CSS3, JavaScript and jquery.
HTML5/CSS3/JavaScript Programming Course Summary Description This class is designed for students that have experience with basic HTML concepts that wish to learn about HTML Version 5, Cascading Style Sheets
More informationBoot Camp JavaScript Sioux, March 31, 2011
Boot Camp JavaScript http://rix0r.nl/bootcamp Sioux, March 31, 2011 Agenda Part 1: JavaScript the Language Short break Part 2: JavaScript in the Browser History May 1995 LiveScript is written by Brendan
More informationJavaScript: the language of browser interactions. Claudia Hauff TI1506: Web and Database Technology
JavaScript: the language of browser interactions Claudia Hauff TI1506: Web and Database Technology ti1506-ewi@tudelft.nl Densest Web lecture of this course. Coding takes time. Be friendly with Codecademy
More informationCE212 Web Application Programming Part 2
CE212 Web Application Programming Part 2 22/01/2018 CE212 Part 2 1 JavaScript Event-Handlers 1 JavaScript may be invoked to handle input events on HTML pages, e.g.
More informationCOMP519 Web Programming Lecture 27: PHP (Part 3) Handouts
COMP519 Web Programming Lecture 27: PHP (Part 3) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool Control
More informationJAVASCRIPT. JavaScript is the programming language of HTML and the Web. JavaScript Java. JavaScript is interpreted by the browser.
JAVASCRIPT JavaScript is the programming language of HTML and the Web. JavaScript Java JavaScript is interpreted by the browser JavaScript 1/15 JS WHERE TO
More informationdhtml2010.pdf February 25,
Dynamic HTML INP 2009/2010 - Client Side Scripting: The DOM and JavaScript Lennart Herlaar lennart@cs.uu.nl http://www.cs.uu.nl/people/lennart room A104, telephone 030-2533921 February 25, 2010 The DOM
More informationPrincess Nourah bint Abdulrahman University. Computer Sciences Department
Princess Nourah bint Abdulrahman University 1 And use http://www.w3schools.com/ JavaScript Objectives Introduction to JavaScript Objects Data Variables Operators Types Functions Events 4 Why Study JavaScript?
More informationITS331 Information Technology I Laboratory
ITS331 Information Technology I Laboratory Laboratory #11 Javascript and JQuery Javascript Javascript is a scripting language implemented as a part of most major web browsers. It directly runs on the client's
More informationThen there are methods ; each method describes an action that can be done to (or with) the object.
When the browser loads a page, it stores it in an electronic form that programmers can then access through something known as an interface. The interface is a little like a predefined set of questions
More informationJavaScript: the Big Picture
JavaScript had to look like Java only less so be Java's dumb kid brother or boy-hostage sidekick. Plus, I had to be done in ten days or something worse than JavaScript would have happened.! JavaScript:
More informationIntroduction to JavaScript p. 1 JavaScript Myths p. 2 Versions of JavaScript p. 2 Client-Side JavaScript p. 3 JavaScript in Other Contexts p.
Preface p. xiii Introduction to JavaScript p. 1 JavaScript Myths p. 2 Versions of JavaScript p. 2 Client-Side JavaScript p. 3 JavaScript in Other Contexts p. 5 Client-Side JavaScript: Executable Content
More informationSample CS 142 Midterm Examination
Sample CS 142 Midterm Examination Winter Quarter 2017 You have 1.5 hours (90 minutes) for this examination; the number of points for each question indicates roughly how many minutes you should spend on
More informationData Visualization (DSC 530/CIS )
Data Visualization (DSC 530/CIS 602-01) JavaScript Dr. David Koop Quiz Given the following HTML, what is the selector for the first div? the super Bowl
More informationVarargs Training & Software Development Centre Private Limited, Module: HTML5, CSS3 & JavaScript
PHP Curriculum Module: HTML5, CSS3 & JavaScript Introduction to the Web o Explain the evolution of HTML o Explain the page structure used by HTML o List the drawbacks in HTML 4 and XHTML o List the new
More informationProduced by. App Development & Modeling. BSc in Applied Computing. Eamonn de Leastar
App Development & Modeling BSc in Applied Computing Produced by Eamonn de Leastar (edeleastar@wit.ie) Department of Computing, Maths & Physics Waterford Institute of Technology http://www.wit.ie http://elearning.wit.ie
More informationCOMP519 Web Programming Lecture 16: JavaScript (Part 7) Handouts
COMP519 Web Programming Lecture 16: JavaScript (Part 7) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool
More informationLEARN WITH INTRODUCTION TO TYPESCRIPT
LEARN WITH INTRODUCTION TO TYPESCRIPT By Jeffry Houser http://www.learn-with.com http://www.jeffryhouser.com https://www.dot-com-it.com Copyright 2017 by DotComIt, LLC Contents Title Page... 2 Introduction
More informationUnobtrusive JavaScript. Lecture Outline. CSE 190 M (Web Programming), Spring 2008 University of Washington
Unobtrusive JavaScript CSE 190 M (Web Programming), Spring 2008 University of Washington Except where otherwise noted, the contents of this presentation are Copyright 2008 Marty Stepp and Jessica Miller
More informationSession 6. JavaScript Part 1. Reading
Session 6 JavaScript Part 1 Reading Reading Wikipedia en.wikipedia.org/wiki/javascript Web Developers Notes www.webdevelopersnotes.com/tutorials/javascript/ JavaScript Debugging www.w3schools.com/js/js_debugging.asp
More informationCITS3403 Agile Web Development Semester 1, 2018
Javascript Event Handling CITS3403 Agile Web Development Semester 1, 2018 Event Driven Programming Event driven programming or event based programming programming paradigm in which the flow of the program
More informationSEEM4570 System Design and Implementation Lecture 03 JavaScript
SEEM4570 System Design and Implementation Lecture 03 JavaScript JavaScript (JS)! Developed by Netscape! A cross platform script language! Mainly used in web environment! Run programs on browsers (HTML
More informationBackground. Javascript is not related to Java in anyway other than trying to get some free publicity
JavaScript I Introduction JavaScript traditionally runs in an interpreter that is part of a browsers Often called a JavaScript engine Was originally designed to add interactive elements to HTML pages First
More informationSession 16. JavaScript Part 1. Reading
Session 16 JavaScript Part 1 1 Reading Reading Wikipedia en.wikipedia.org/wiki/javascript / p W3C www.w3.org/tr/rec-html40/interact/scripts.html Web Developers Notes www.webdevelopersnotes.com/tutorials/javascript/
More informationCSC Web Programming. JavaScript Browser Objects
CSC 242 - Web Programming JavaScript Browser Objects JavaScript Object Types User defined objects Native objects (Array, Math, Date, etc.) Host Objects provided by the browser The window object is a representation
More informationFunctions. Functions in JavaScript are declared using the function keyword
JavaScript II Functions Functions in JavaScript are declared using the function keyword function function_name(args){ Functions are rst class objects, they are stored in variables like everything else
More informationWorking with JavaScript
Working with JavaScript Creating a Programmable Web Page for North Pole Novelties 1 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page 2 Objectives
More informationData Visualization (DSC 530/CIS )
Data Visualization (DSC 530/CIS 602-02) Web Programming Dr. David Koop 2 What languages do we use on the Web? 3 Languages of the Web HTML CSS SVG JavaScript - Versions of Javascript: ES6, ES2015, ES2017
More informationSession 7. JavaScript Part 2. W3C DOM Reading and Reference
Session 7 JavaScript Part 2 W3C DOM Reading and Reference Background and introduction developer.mozilla.org/en-us/docs/dom/dom_reference/introduction en.wikipedia.org/wiki/document_object_model www.w3schools.com/js/js_htmldom.asp
More informationJavaScript CS 4640 Programming Languages for Web Applications
JavaScript CS 4640 Programming Languages for Web Applications 1 How HTML, CSS, and JS Fit Together {css} javascript() Content layer The HTML gives the page structure and adds semantics Presentation
More informationComputer Science II (20082) Week 1: Review and Inheritance
Computer Science II 4003-232-08 (20082) Week 1: Review and Inheritance Richard Zanibbi Rochester Institute of Technology Review of CS-I Syntax and Semantics of Formal (e.g. Programming) Languages Syntax
More informationJavaScript Specialist v2.0 Exam 1D0-735
JavaScript Specialist v2.0 Exam 1D0-735 Domain 1: Essential JavaScript Principles and Practices 1.1: Identify characteristics of JavaScript and common programming practices. 1.1.1: List key JavaScript
More informationCERTIFICATE IN WEB PROGRAMMING
COURSE DURATION: 6 MONTHS CONTENTS : CERTIFICATE IN WEB PROGRAMMING 1. PROGRAMMING IN C and C++ Language 2. HTML/CSS and JavaScript 3. PHP and MySQL 4. Project on Development of Web Application 1. PROGRAMMING
More informationJavaScript CS 4640 Programming Languages for Web Applications
JavaScript CS 4640 Programming Languages for Web Applications 1 How HTML, CSS, and JS Fit Together {css} javascript() Content layer The HTML gives the page structure and adds semantics Presentation
More informationAs we design and build out our HTML pages, there are some basics that we may follow for each page, site, and application.
Extra notes - Client-side Design and Development Dr Nick Hayward HTML - Basics A brief introduction to some of the basics of HTML. Contents Intro element add some metadata define a base address
More informationINF5750. Introduction to JavaScript and Node.js
INF5750 Introduction to JavaScript and Node.js Outline Introduction to JavaScript Language basics Introduction to Node.js Tips and tools for working with JS and Node.js What is JavaScript? Built as scripting
More informationPES DEGREE COLLEGE BANGALORE SOUTH CAMPUS 1 K.M. before Electronic City, Bangalore WEB PROGRAMMING Solution Set II
PES DEGREE COLLEGE BANGALORE SOUTH CAMPUS 1 K.M. before Electronic City, Bangalore 560 100 WEB PROGRAMMING Solution Set II Section A 1. This function evaluates a string as javascript statement or expression
More informationChapter 6 How to script the DOM with JavaScript
Chapter 6 How to script the DOM with JavaScript Murach's JavaScript and jquery, C6 2012, Mike Murach & Associates, Inc. Slide 1 Objectives Applied 1. Use the properties and methods of the Node, Document,
More informationChapter 16. JavaScript 3: Functions Table of Contents
Chapter 16. JavaScript 3: Functions Table of Contents Objectives... 2 14.1 Introduction... 2 14.1.1 Introduction to JavaScript Functions... 2 14.1.2 Uses of Functions... 2 14.2 Using Functions... 2 14.2.1
More informationA.A. 2008/09. Why introduce JavaScript. G. Cecchetti Internet Software Technologies
Internet t Software Technologies JavaScript part one IMCNE A.A. 2008/09 Gabriele Cecchetti Why introduce JavaScript To add dynamicity and interactivity to HTML pages 2 What s a script It s a little interpreted
More informationIntroduction to using HTML to design webpages
Introduction to using HTML to design webpages #HTML is the script that web pages are written in. It describes the content and structure of a web page so that a browser is able to interpret and render the
More informationJavaScript: Events, the DOM Tree, jquery and Timing
JavaScript: Events, the DOM Tree, jquery and Timing CISC 282 October 11, 2017 window.onload Conflict Can only set window.onload = function once What if you have multiple files for handlers? What if you're
More informationCOMS W3101: SCRIPTING LANGUAGES: JAVASCRIPT (FALL 2018)
COMS W3101: SCRIPTING LANGUAGES: JAVASCRIPT (FALL 2018) RAMANA ISUKAPALLI RAMANA@CS.COLUMBIA.EDU 1 LECTURE-1 Course overview See http://www.cs.columbia.edu/~ramana Overview of HTML Formatting, headings,
More informationSuch JavaScript Very Wow
Such JavaScript Very Wow Lecture 9 CGS 3066 Fall 2016 October 20, 2016 JavaScript Numbers JavaScript numbers can be written with, or without decimals. Extra large or extra small numbers can be written
More informationJavaScript: Events, DOM and Attaching Handlers
JavaScript: Events, DOM and Attaching Handlers CISC 282 October 11, 2017 Keyboard and Text Events Name The User Must Applicable Elements blur remove focus , ,... focus apply focus , ,...
More informationJavaScript and XHTML. Prof. D. Krupesha, PESIT, Bangalore
JavaScript and XHTML Prof. D. Krupesha, PESIT, Bangalore Why is JavaScript Important? It is simple and lots of scripts available in public domain and easy to use. It is used for client-side scripting.
More informationTizen Web UI Technologies (Tizen Ver. 2.3)
Tizen Web UI Technologies (Tizen Ver. 2.3) Spring 2015 Soo Dong Kim, Ph.D. Professor, Department of Computer Science Software Engineering Laboratory Soongsil University Office 02-820-0909 Mobile 010-7392-2220
More informationData Visualization (CIS 468)
Data Visualization (CIS 468) Web Programming Dr. David Koop Languages of the Web HTML CSS SVG JavaScript - Versions of Javascript: ES6/ES2015, ES2017 - Specific frameworks: react, jquery, bootstrap, D3
More informationCOMS W3101: SCRIPTING LANGUAGES: JAVASCRIPT (FALL 2017)
COMS W3101: SCRIPTING LANGUAGES: JAVASCRIPT (FALL 2017) RAMANA ISUKAPALLI RAMANA@CS.COLUMBIA.EDU 1 LECTURE-1 Course overview See http://www.cs.columbia.edu/~ramana Overview of HTML Formatting, headings,
More informationJavaScript: Introduction, Types
JavaScript: Introduction, Types Computer Science and Engineering College of Engineering The Ohio State University Lecture 19 History Developed by Netscape "LiveScript", then renamed "JavaScript" Nothing
More informationCHAPTER 6 JAVASCRIPT PART 1
CHAPTER 6 JAVASCRIPT PART 1 1 OVERVIEW OF JAVASCRIPT JavaScript is an implementation of the ECMAScript language standard and is typically used to enable programmatic access to computational objects within
More information(Refer Slide Time: 01:40)
Internet Technology Prof. Indranil Sengupta Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture No #25 Javascript Part I Today will be talking about a language
More informationEECS1012. Net-centric Introduction to Computing. Lecture Introduction to Javascript
EECS 1012 Net-centric Introduction to Computing Lecture Introduction to Javascript Acknowledgements Contents are adapted from web lectures for Web Programming Step by Step, by M. Stepp, J. Miller, and
More informationJavaScript Programming
JavaScript Programming Course ISI-1337B - 5 Days - Instructor-led, Hands on Introduction Today, JavaScript is used in almost 90% of all websites, including the most heavilytrafficked sites like Google,
More informationJavaScript. Training Offer for JavaScript Introduction JavaScript. JavaScript Objects
JavaScript CAC Noida is an ISO 9001:2015 certified training center with professional experience that dates back to 2005. The vision is to provide professional education merging corporate culture globally
More informationQ1. What is JavaScript?
Q1. What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight programming language JavaScript is usually embedded
More informationCGS 3066: Spring 2015 JavaScript Reference
CGS 3066: Spring 2015 JavaScript Reference Can also be used as a study guide. Only covers topics discussed in class. 1 Introduction JavaScript is a scripting language produced by Netscape for use within
More information<form>. input elements. </form>
CS 183 4/8/2010 A form is an area that can contain form elements. Form elements are elements that allow the user to enter information (like text fields, text area fields, drop-down menus, radio buttons,
More informationPlace User-Defined Functions in the HEAD Section
JavaScript Functions Notes (Modified from: w3schools.com) A function is a block of code that will be executed when "someone" calls it. In JavaScript, we can define our own functions, called user-defined
More informationCSS The web browser uses its own resources, and eases the burden on the server. It has fewer features than server side scripting.
What is JavaScript? HTML and CSS concentrate on a static rendering of a page; things do not change on the page over time, or because of events. To do these things, we use scripting languages, which allow
More informationMidterm Exam. 5. What is the character - (minus) used for in JavaScript? Give as many answers as you can.
First Name Last Name CSCi 90.3 March 23, 2010 Midterm Exam Instructions: For multiple choice questions, circle the letter of the one best choice unless the question explicitly states that it might have
More informationCOMP284 Scripting Languages Lecture 14: JavaScript (Part 1) Handouts
COMP284 Scripting Languages Lecture 14: JavaScript (Part 1) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool
More informationAbstract Classes and Polymorphism CSC 123 Fall 2018 Howard Rosenthal
Abstract Classes and Polymorphism CSC 123 Fall 2018 Howard Rosenthal Lesson Goals Define and discuss abstract classes Define and discuss abstract methods Introduce polymorphism Much of the information
More informationWeb Site Design and Development JavaScript
Web Site Design and Development JavaScript CS 0134 Fall 2018 Tues and Thurs 1:00 2:15PM JavaScript JavaScript is a programming language that was designed to run in your web browser. 2 Some Definitions
More informationGrow with Google Challenge Scholarship Front-End Web Dev Notebook
Grow with Google Challenge Scholarship Front-End Web Dev Notebook 1 Table of Contents Table of Contents HTML Syntax Elements and Tags Elements Example HTML Element: Paragraph element: Tags Example Tag:
More informationisnan function returns true if the argument is not a number otherwise it is false.
1. What is JavaScript? JavaScript is a client-side as well as server side scripting language that can be inserted into HTML pages and is understood by web browsers. JavaScript is also an Object Oriented
More informationOO and Ahh! An Introduction to Object Oriented Programming With PHP. Division 1 Systems. John Valance. Copyright John Valance Division 1 Systems
OO and Ahh! An Introduction to Object Oriented Programming With PHP John Valance Division 1 Systems johnv@div1sys.com Copyright John Valance Division 1 Systems About John Valance 30+ years IBM midrange
More informationChapter4: HTML Table and Script page, HTML5 new forms. Asst. Prof. Dr. Supakit Nootyaskool Information Technology, KMITL
Chapter4: HTML Table and Script page, HTML5 new forms Asst. Prof. Dr. Supakit Nootyaskool Information Technology, KMITL Objective To know HTML5 creating a new style form. To understand HTML table benefits
More informationVariables and Typing
Variables and Typing Christopher M. Harden Contents 1 The basic workflow 2 2 Variables 3 2.1 Declaring a variable........................ 3 2.2 Assigning to a variable...................... 4 2.3 Other
More informationWeb Programming/Scripting: JavaScript
CS 312 Internet Concepts Web Programming/Scripting: JavaScript Dr. Michele Weigle Department of Computer Science Old Dominion University mweigle@cs.odu.edu http://www.cs.odu.edu/~mweigle/cs312-f11/ 1 Outline!
More informationManju Muralidharan Priya. CS4PM Web Aesthetics and Development WEEK 11
CS4PM Web Aesthetics and Development WEEK 11 Objective: Understand basics of JScript Outline: a. Basics of JScript Reading: Refer to w3schools websites and use the TRY IT YOURSELF editor and play with
More informationwidgetjs Documentation
widgetjs Documentation Release 1.2.3 Nicolas Vanhoren Dec 22, 2017 Contents 1 Tutorial 3 1.1 Presentation of widgetjs......................................... 3 1.2 Quickstart................................................
More informationControlled Assessment Task. Question 1 - Describe how this HTML code produces the form displayed in the browser.
Controlled Assessment Task Question 1 - Describe how this HTML code produces the form displayed in the browser. The form s code is displayed in the tags; this creates the object which is the visible
More informationExercise 1 Using Boolean variables, incorporating JavaScript code into your HTML webpage and using the document object
CS1046 Lab 5 Timing: This lab should take you approximately 2 hours. Objectives: By the end of this lab you should be able to: Recognize a Boolean variable and identify the two values it can take Calculate
More information