SlideShare a Scribd company logo
JavaScript for Web
Developer
ZUBZIB BLACK COFFEE #8
CHALERMPON AREEPONG (NINE)
AGENDA
Basic Programming
Object Oriented Programming
3rd JavaScript Libraries
AJAX, JSON, Handle Event
Debugging
Unit Test
MVC
JavaScript (JS)
Created in 1995 by Brendan Eich
Name: Mocha in LAB, LiveScript for Netscape Navigator 2.0 and last rename to
JavaScript with Netscape 2 beta in December 1995
Microsoft add JavaScript to IE in 1996 called JScript
Brendan Eich
Java script for web developer
Stuff You Should Know
JavaScript run in Web Browser
JavaScript integrate with DOM
JavaScript is a dynamic type
Current JavaScript complied to ECMA-262 version 5.1
http://en.wikipedia.org/wiki/ECMAScript
JavaScript no coding standard, has only Best Practice
JavaScript IDE Tools
Web Browser Developer Tool
◦ Chrome (F12)
◦ Firefox add-in Firebug (F12)
◦ IE (F12)
◦ Safari
◦ Others
JavaScript IDE Tools
IDE Setup
◦ Visual Studio
◦ WebMatrix
◦ Kineticwing
◦ WebStrom
◦ CodeMirror
◦ Other
http://en.wikipedia.org/wiki/Comparison
_of_JavaScript-
based_source_code_editors
Cloud IDE
◦ Cloud9
◦ CodeAnywhere
◦ Cloud IDE
◦ Sourcekit
◦ Codepen, jsfiddle, jsbin
◦ Other
http://www.hongkiat.com/blog/cloud-
ide-developers/
Demo tool
Chrome
jsfiddle
Visual Studio 2012 Update 3
Resharper 8
JavaScript Basic Programming
Declare Variable
var testString = 'ASP.NET & MVC Developers Thailand';
var testInt = 2000;
var testBool = true;
var testDouble = 2000.2334;
var testReg = /(?:.d){2}/;
var testUndefined;
var testNull = null;
var testArray = new [0, 1, 2, 3];
var testObj = new {};
var testFunc = new function () { };
JavaScript Basic Programming
Declare Function
//Declare function
function MVCShowOff() { return "Hi there, we are X!!"; }
var message = MVCShowOff(); //call
//Declare varriable function
var MvcShowOff = function () { return "Hi there, we are X!!"; };
message = MvcShowOff(); //call
//Declare Self-Invoking function
(function () { return "Hi there, we are X!!"; })();//<-- (); is a caller
//Declare Annonymous Function
document.onload = function (e) { alert("Hi there, we are X!!"); };
JavaScript Basic Programming
Parameter Function
//Declare Function with parameter
function Mid2Vals(hi, low) { return (hi + low) / 2; }
var result = Mid2Vals(5, 10);
//Declare Function without parameter and use arguments parameter
function Mid2Vals() { return (arguments[0] + arguments[1]) / 2; }
var result = Mid2Vals(5, 10);
JavaScript Basic Programming
Class and Object
//1. Declare Object Type, Class
function MvcMember() {
this.name = "Nine not K9";
this.isInstuctor = true;
};
//Declare varriable and call
var mrNine = new MvcMember();
alert(mrNine.isInstuctor); // true
//2. Declare Object literal
var mrNine = {
name : "Nine not K9",
isInstuctor : true
};
//Call
alert(mrNine.isInstuctor); // true
JavaScript Basic Programming
Complex Class Object
//1. Declare Class
function MvcMember() {
this.name = "Nine not K9";
this.isInstuctor = true;
this.event = new function Event() {
this.name = "Zubzib Black Coffee #5 Update Skills v1";
this.session = new function Session() {
this.name = "JavaScript for Web Developer";
this.audiences = 40; };
this.place = "University of Thai Chamber of Commerce";
this.location = new function Location() {
this.lat = 13.779276;
this.long = 100.560326;
this.getGeoLocation = lat + ', ' + long; };};};
//2. Initial varriable and access data
var mrNine = new MvcMember();
alert(mrNine.event.name);
alert(mrNine.event.session.name);
alert(mrNine.event.location.getGeoLocation);
JavaScript Basic Programming
Late Declare Variable and Function
//1. Declare Class
function MvcMember() {
this.name = "Nine not K9";
this.isInstuctor = true;
};
//And initial an object
var mrNine = new MvcMember();
//2. late declare variable
mrNine.say = "Hi everybody"; // mrNine["say"] = "Hi everybody"; //same
//3. late declare function
mrNine.thinkAbout = function (source) { return "I'm thinking about the " + source; };
JavaScript Basic Programming
Condition, Loop, try… catch
//IF Else condition
var x = 0, y = 1;
if (x == 1) { alert('Yes'); }
else { alert('No'); }
//Switch Condition
var word = "Hi";
switch (word) {
case "Hi":
alert('How r u?');
default:
alert("Hey what's was wrong with you?");
}
//While loop
var x = 5;
while (x<1) { x--; }
alert(x);
//For loop
var title = "JavaScript".split('');
for (var i = 0; i < title.length; i++) {
alert(title[i]);
}
JavaScript Basic Programming
Condition, Loop, try… catch
// For Each Loop
var topic = "JavaScript very easy".split(' ');
topic.forEach(function(word) { alert(word); });
//try catch block
try {
var x;
x.ErrorPlease();
} catch(e) {
alert("catch error : " + e.message);
}
JavaScript Basic Programming
Comparisons 1
// Assigh value
var x = 10;
console.log("x="+x);
//Comparison
var a = "test", b = "TEST";
var result = a == b;
console.log("comparison a == b ? "+result);
//Identity
var identityResult = a === x;
console.log("identity a is b ? " + identityResult);
JavaScript Basic Programming
Comparison 2
//check base type and value type
var undef;
var num = 90;
var str = "Test";
var bool = true;
var func = function (a, b) { return a + b; };
var object = { x: 500 };
var arr = ["Nine", "Non", "Tape"];
console.log(typeof undef); //"undefined"
console.log(typeof num); //"number"
console.log(typeof str); //"string"
console.log(typeof bool); //"boolean"
console.log(typeof func); //"function"
console.log(typeof object); // "object"
console.log(typeof arr); // "object"
//check object instance of class
var arr = ["Nine", "Non", "Tape"];
console.log(arr instanceof Array); // true
function Speaker() { this.name = "Nine"; }
var mrNine = new Speaker();
console.log(mrNine instanceof Speaker); // true
JavaScript Basic Programming
Value of variables are always false in condition
var a = null;
var b; // undefined
var c = 0;
var d = false;
var e = "";
if (a) // false
if (b) // false
if (c) // false
if (d) // false
if (e) // false
JavaScript Basic Programming
Inheritance with Prototype
function Speaker(isSpeaking) { this.isSpeaking = isSpeaking == null ? false :
isSpeaking; }
Speaker.prototype.say = function () {return "Break session"; };
function ZZSpeaker () { this.isEating = true; }
ZZSpeaker.prototype = new Speaker();
ZZSpeaker.prototype.sleepyShow = function () { alert('wake up !!!'); };
ZZSpeaker.prototype.say = function () { return "Ask me please.."; };
var nineSpeak = new ZZSpeaker();
nineSpeak.say();
nineSpeak.sleepyShow();
3rd JavaScript Framework and
Library
jQuery is a library created on top JavaScript, to help us access DOM and populate HTML
element, content , CSS, animation and DOM Event
The two thinks jQuery dose
1. SELECT elements or a group of element by CSS Selector
2. Take Action on elements
3rd JavaScript Framework and
Library
jQuery : Get Started
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div class="test"></div>
<!-- 1. Add script reference to local or CDN -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
//2. declare document ready
$(document).ready(function () {
$('div.test').html("<h1>JavaScript for web developer</h1>");
});
</script>
</body>
</html>
3rd JavaScript Framework and
Library
jQuery : query and action
<div class="test"></div>
<input id="btnShowMessage" type="button" value="click me" />
//2. declare document ready
$(document).ready(function () {
//3. Bind Element Action to custom function
$('#btnShowMessage').click(function () {
$('div.test').html("<h1>DOM Ready binding event</h1>");
});
});
//4. Early binding event can declare out of DOM Ready block
$('#btnShowMessage').on('click', function () {
$('div.test').html("<h1>Early binding event</h1>");
});
Java script for web developer
AJAX ????
Java script for web developer
AJAX: Asynchronous JavaScript and
XML
None blocking user action and no screen freeze
Use AJAX (native code)
// This is the client-side script
// Initialize the Ajax request
var xhr = XMLHttpRequest();
xhr.open('get', 'http://google.com');
// Track the state changes of the request
xhr.onreadystatechange = function () {
// Ready state 4 means the request is done
if (xhr.readyState === 4) {
// 200 is a successful return
if (xhr.status === 200) {
alert(xhr.responseText); // 'This is the returned text.'
} else {
alert('Error: ' + xhr.status); // An error occurred during the request
} }}
// Send the request to send-ajax-data.php
xhr.send(null);
Use AJAX with JQUERY
$.get()
$.post()
$.getJSON()
$.ajax()
Demo
$.get('ajax/test.html', function (data) {
$('.result').html(data);
alert('Load was performed.');
});
$.post('ajax/test.html', function (data) {
$('.result').html(data);
});
$.getJSON('ajax/test.json', function (data) {
var items = [];
$.each(data, function (key, val) {
items.push('<li id="' + key + '">' + val + '</li>');
});
});
JSON ????
Java script for web developer
JSON : JavaScript Object Notation
JSON is a text-based open standard designed for human-readable data interchange
//JavaScript Object
var session = { name: 'Nine', sessionName: 'JavaScript for Web Developer', };
//JSON Object
{"name": "Nine", "sessionName" : "JavaScript for Web Developer" }
JSON
JavaScript Object to JSON
var session = { name: $('input#name').val(), sessionName:
$('input#sesseionName').val() };
//convert to json
var json = JSON.stringify(session);
JSON
Demo JSON
Debug JavaScript
JavaScript Debugger Tools
1. Browser Web Developer Tools (F12)
2. Visual Studio 2012 + IE10 or later
Debug JavaScript
Put break point and click html button
JavaScript Unit Testing
article
MVC power by AngularJS
article

More Related Content

What's hot (20)

PDF
JavaScript 101
ygv2000
 
PDF
Fundamental JavaScript [UTC, March 2014]
Aaron Gustafson
 
PPTX
Promises, Promises
Domenic Denicola
 
ODP
Supercharging reflective libraries with InvokeDynamic
Ian Robertson
 
PPTX
AngularJS with TypeScript and Windows Azure Mobile Services
Rainer Stropek
 
PDF
Jasmine - why JS tests don't smell fishy
Igor Napierala
 
PPTX
Javascript basics for automation testing
Vikas Thange
 
PDF
Java Script Best Practices
Enrique Juan de Dios
 
PDF
Redux for ReactJS Programmers
David Rodenas
 
PDF
Advanced javascript
Doeun KOCH
 
PDF
A Re-Introduction to JavaScript
Simon Willison
 
PPTX
Workshop 1: Good practices in JavaScript
Visual Engineering
 
PDF
$q and Promises in AngularJS
a_sharif
 
PPTX
Solid Software Design Principles
Jon Kruger
 
PDF
Workshop 5: JavaScript testing
Visual Engineering
 
PPTX
Good karma: UX Patterns and Unit Testing in Angular with Karma
ExoLeaders.com
 
PDF
What's up with Prototype and script.aculo.us?
Christophe Porteneuve
 
PDF
Workshop 10: ECMAScript 6
Visual Engineering
 
PDF
Callbacks and control flow in Node js
Thomas Roch
 
PPTX
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Jon Kruger
 
JavaScript 101
ygv2000
 
Fundamental JavaScript [UTC, March 2014]
Aaron Gustafson
 
Promises, Promises
Domenic Denicola
 
Supercharging reflective libraries with InvokeDynamic
Ian Robertson
 
AngularJS with TypeScript and Windows Azure Mobile Services
Rainer Stropek
 
Jasmine - why JS tests don't smell fishy
Igor Napierala
 
Javascript basics for automation testing
Vikas Thange
 
Java Script Best Practices
Enrique Juan de Dios
 
Redux for ReactJS Programmers
David Rodenas
 
Advanced javascript
Doeun KOCH
 
A Re-Introduction to JavaScript
Simon Willison
 
Workshop 1: Good practices in JavaScript
Visual Engineering
 
$q and Promises in AngularJS
a_sharif
 
Solid Software Design Principles
Jon Kruger
 
Workshop 5: JavaScript testing
Visual Engineering
 
Good karma: UX Patterns and Unit Testing in Angular with Karma
ExoLeaders.com
 
What's up with Prototype and script.aculo.us?
Christophe Porteneuve
 
Workshop 10: ECMAScript 6
Visual Engineering
 
Callbacks and control flow in Node js
Thomas Roch
 
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Jon Kruger
 

Viewers also liked (11)

PDF
JavaScript for Beginners
Edward Gilligan III.
 
PDF
Powershell Certificate
Edward Gilligan III.
 
PDF
JavaScript
tutorialsruby
 
PDF
Dom API In Java Script
Rajat Pandit
 
PDF
JavaScript Library Overview
jeresig
 
PDF
Javascript & DOM - Part 1- Javascript Tutorial for Beginners with Examples
OUM SAOKOSAL
 
PPSX
DIWE - Programming with JavaScript
Rasan Samarasinghe
 
PDF
Le Wagon - Javascript for Beginners
Sébastien Saunier
 
PDF
Unobtrusive JavaScript with jQuery
Simon Willison
 
PPTX
Maintainable JavaScript 2012
Nicholas Zakas
 
PDF
Writing Efficient JavaScript
Nicholas Zakas
 
JavaScript for Beginners
Edward Gilligan III.
 
Powershell Certificate
Edward Gilligan III.
 
JavaScript
tutorialsruby
 
Dom API In Java Script
Rajat Pandit
 
JavaScript Library Overview
jeresig
 
Javascript & DOM - Part 1- Javascript Tutorial for Beginners with Examples
OUM SAOKOSAL
 
DIWE - Programming with JavaScript
Rasan Samarasinghe
 
Le Wagon - Javascript for Beginners
Sébastien Saunier
 
Unobtrusive JavaScript with jQuery
Simon Willison
 
Maintainable JavaScript 2012
Nicholas Zakas
 
Writing Efficient JavaScript
Nicholas Zakas
 
Ad

Similar to Java script for web developer (20)

PDF
JavaScript Core
François Sarradin
 
PDF
Javascript: the important bits
Chris Saylor
 
PDF
The Beauty Of Java Script V5a
rajivmordani
 
PDF
The Beauty of Java Script
Michael Girouard
 
PDF
HTML5 for the Silverlight Guy
David Padbury
 
PDF
Javascript Frameworks for Joomla
Luke Summerfield
 
PPT
Introduction to Javascript
Amit Tyagi
 
KEY
JavaScript Neednt Hurt - JavaBin talk
Thomas Kjeldahl Nilsson
 
PDF
How to make Ajax work for you
Simon Willison
 
PDF
Construire une application JavaFX 8 avec gradle
Thierry Wasylczenko
 
PPT
Expert JavaScript tricks of the masters
Ara Pehlivanian
 
PDF
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
GITS Indonesia
 
KEY
JavaScript Growing Up
David Padbury
 
PDF
JavaScript straight from the Oracle Database
Dimitri Gielis
 
PDF
Javascript & Ajax Basics
Richard Paul
 
PDF
Avinash Kundaliya: Javascript and WordPress
wpnepal
 
PPT
JavaScript Misunderstood
Bhavya Siddappa
 
PDF
The Open Web and what it means
Robert Nyman
 
PDF
2013-06-15 - Software Craftsmanship mit JavaScript
Johannes Hoppe
 
JavaScript Core
François Sarradin
 
Javascript: the important bits
Chris Saylor
 
The Beauty Of Java Script V5a
rajivmordani
 
The Beauty of Java Script
Michael Girouard
 
HTML5 for the Silverlight Guy
David Padbury
 
Javascript Frameworks for Joomla
Luke Summerfield
 
Introduction to Javascript
Amit Tyagi
 
JavaScript Neednt Hurt - JavaBin talk
Thomas Kjeldahl Nilsson
 
How to make Ajax work for you
Simon Willison
 
Construire une application JavaFX 8 avec gradle
Thierry Wasylczenko
 
Expert JavaScript tricks of the masters
Ara Pehlivanian
 
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
GITS Indonesia
 
JavaScript Growing Up
David Padbury
 
JavaScript straight from the Oracle Database
Dimitri Gielis
 
Javascript & Ajax Basics
Richard Paul
 
Avinash Kundaliya: Javascript and WordPress
wpnepal
 
JavaScript Misunderstood
Bhavya Siddappa
 
The Open Web and what it means
Robert Nyman
 
2013-06-15 - Software Craftsmanship mit JavaScript
Johannes Hoppe
 
Ad

More from Chalermpon Areepong (10)

PPTX
DevRock #02 akka.net intro part
Chalermpon Areepong
 
PPTX
Web API authentication and authorization
Chalermpon Areepong
 
PDF
Build your website with angularjs and web apis
Chalermpon Areepong
 
PPTX
ASP.NET WEB API Training
Chalermpon Areepong
 
PPTX
ZZ BC#8 Hello ASP.NET MVC 4 (dks)
Chalermpon Areepong
 
PPTX
ZZ BC#7.5 asp.net mvc practice and guideline refresh!
Chalermpon Areepong
 
PPTX
ZZ BC#7 asp.net mvc practice and guideline by NineMvp
Chalermpon Areepong
 
PPTX
Build your web app with asp.net mvc 2 from scratch
Chalermpon Areepong
 
PPTX
Gf vtzz-05--j queryshowcase
Chalermpon Areepong
 
PPTX
J query
Chalermpon Areepong
 
DevRock #02 akka.net intro part
Chalermpon Areepong
 
Web API authentication and authorization
Chalermpon Areepong
 
Build your website with angularjs and web apis
Chalermpon Areepong
 
ASP.NET WEB API Training
Chalermpon Areepong
 
ZZ BC#8 Hello ASP.NET MVC 4 (dks)
Chalermpon Areepong
 
ZZ BC#7.5 asp.net mvc practice and guideline refresh!
Chalermpon Areepong
 
ZZ BC#7 asp.net mvc practice and guideline by NineMvp
Chalermpon Areepong
 
Build your web app with asp.net mvc 2 from scratch
Chalermpon Areepong
 
Gf vtzz-05--j queryshowcase
Chalermpon Areepong
 

Recently uploaded (20)

PPTX
Practical Applications of AI in Local Government
OnBoard
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
PPTX
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
Sound the Alarm: Detection and Response
VICTOR MAESTRE RAMIREZ
 
PDF
Next Generation AI: Anticipatory Intelligence, Forecasting Inflection Points ...
dleka294658677
 
PPTX
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
PPTX
CapCut Pro PC Crack Latest Version Free Free
josanj305
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PDF
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
PDF
GDG Cloud Southlake #44: Eyal Bukchin: Tightening the Kubernetes Feedback Loo...
James Anderson
 
PDF
Kubernetes - Architecture & Components.pdf
geethak285
 
PDF
Deploy Faster, Run Smarter: Learn Containers with QNAP
QNAP Marketing
 
PDF
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
PDF
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PPTX
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
Practical Applications of AI in Local Government
OnBoard
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
Sound the Alarm: Detection and Response
VICTOR MAESTRE RAMIREZ
 
Next Generation AI: Anticipatory Intelligence, Forecasting Inflection Points ...
dleka294658677
 
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
CapCut Pro PC Crack Latest Version Free Free
josanj305
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
GDG Cloud Southlake #44: Eyal Bukchin: Tightening the Kubernetes Feedback Loo...
James Anderson
 
Kubernetes - Architecture & Components.pdf
geethak285
 
Deploy Faster, Run Smarter: Learn Containers with QNAP
QNAP Marketing
 
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 

Java script for web developer

  • 1. JavaScript for Web Developer ZUBZIB BLACK COFFEE #8 CHALERMPON AREEPONG (NINE)
  • 2. AGENDA Basic Programming Object Oriented Programming 3rd JavaScript Libraries AJAX, JSON, Handle Event Debugging Unit Test MVC
  • 3. JavaScript (JS) Created in 1995 by Brendan Eich Name: Mocha in LAB, LiveScript for Netscape Navigator 2.0 and last rename to JavaScript with Netscape 2 beta in December 1995 Microsoft add JavaScript to IE in 1996 called JScript
  • 6. Stuff You Should Know JavaScript run in Web Browser JavaScript integrate with DOM JavaScript is a dynamic type Current JavaScript complied to ECMA-262 version 5.1 http://en.wikipedia.org/wiki/ECMAScript JavaScript no coding standard, has only Best Practice
  • 7. JavaScript IDE Tools Web Browser Developer Tool ◦ Chrome (F12) ◦ Firefox add-in Firebug (F12) ◦ IE (F12) ◦ Safari ◦ Others
  • 8. JavaScript IDE Tools IDE Setup ◦ Visual Studio ◦ WebMatrix ◦ Kineticwing ◦ WebStrom ◦ CodeMirror ◦ Other http://en.wikipedia.org/wiki/Comparison _of_JavaScript- based_source_code_editors Cloud IDE ◦ Cloud9 ◦ CodeAnywhere ◦ Cloud IDE ◦ Sourcekit ◦ Codepen, jsfiddle, jsbin ◦ Other http://www.hongkiat.com/blog/cloud- ide-developers/
  • 9. Demo tool Chrome jsfiddle Visual Studio 2012 Update 3 Resharper 8
  • 10. JavaScript Basic Programming Declare Variable var testString = 'ASP.NET & MVC Developers Thailand'; var testInt = 2000; var testBool = true; var testDouble = 2000.2334; var testReg = /(?:.d){2}/; var testUndefined; var testNull = null; var testArray = new [0, 1, 2, 3]; var testObj = new {}; var testFunc = new function () { };
  • 11. JavaScript Basic Programming Declare Function //Declare function function MVCShowOff() { return "Hi there, we are X!!"; } var message = MVCShowOff(); //call //Declare varriable function var MvcShowOff = function () { return "Hi there, we are X!!"; }; message = MvcShowOff(); //call //Declare Self-Invoking function (function () { return "Hi there, we are X!!"; })();//<-- (); is a caller //Declare Annonymous Function document.onload = function (e) { alert("Hi there, we are X!!"); };
  • 12. JavaScript Basic Programming Parameter Function //Declare Function with parameter function Mid2Vals(hi, low) { return (hi + low) / 2; } var result = Mid2Vals(5, 10); //Declare Function without parameter and use arguments parameter function Mid2Vals() { return (arguments[0] + arguments[1]) / 2; } var result = Mid2Vals(5, 10);
  • 13. JavaScript Basic Programming Class and Object //1. Declare Object Type, Class function MvcMember() { this.name = "Nine not K9"; this.isInstuctor = true; }; //Declare varriable and call var mrNine = new MvcMember(); alert(mrNine.isInstuctor); // true //2. Declare Object literal var mrNine = { name : "Nine not K9", isInstuctor : true }; //Call alert(mrNine.isInstuctor); // true
  • 14. JavaScript Basic Programming Complex Class Object //1. Declare Class function MvcMember() { this.name = "Nine not K9"; this.isInstuctor = true; this.event = new function Event() { this.name = "Zubzib Black Coffee #5 Update Skills v1"; this.session = new function Session() { this.name = "JavaScript for Web Developer"; this.audiences = 40; }; this.place = "University of Thai Chamber of Commerce"; this.location = new function Location() { this.lat = 13.779276; this.long = 100.560326; this.getGeoLocation = lat + ', ' + long; };};}; //2. Initial varriable and access data var mrNine = new MvcMember(); alert(mrNine.event.name); alert(mrNine.event.session.name); alert(mrNine.event.location.getGeoLocation);
  • 15. JavaScript Basic Programming Late Declare Variable and Function //1. Declare Class function MvcMember() { this.name = "Nine not K9"; this.isInstuctor = true; }; //And initial an object var mrNine = new MvcMember(); //2. late declare variable mrNine.say = "Hi everybody"; // mrNine["say"] = "Hi everybody"; //same //3. late declare function mrNine.thinkAbout = function (source) { return "I'm thinking about the " + source; };
  • 16. JavaScript Basic Programming Condition, Loop, try… catch //IF Else condition var x = 0, y = 1; if (x == 1) { alert('Yes'); } else { alert('No'); } //Switch Condition var word = "Hi"; switch (word) { case "Hi": alert('How r u?'); default: alert("Hey what's was wrong with you?"); } //While loop var x = 5; while (x<1) { x--; } alert(x); //For loop var title = "JavaScript".split(''); for (var i = 0; i < title.length; i++) { alert(title[i]); }
  • 17. JavaScript Basic Programming Condition, Loop, try… catch // For Each Loop var topic = "JavaScript very easy".split(' '); topic.forEach(function(word) { alert(word); }); //try catch block try { var x; x.ErrorPlease(); } catch(e) { alert("catch error : " + e.message); }
  • 18. JavaScript Basic Programming Comparisons 1 // Assigh value var x = 10; console.log("x="+x); //Comparison var a = "test", b = "TEST"; var result = a == b; console.log("comparison a == b ? "+result); //Identity var identityResult = a === x; console.log("identity a is b ? " + identityResult);
  • 19. JavaScript Basic Programming Comparison 2 //check base type and value type var undef; var num = 90; var str = "Test"; var bool = true; var func = function (a, b) { return a + b; }; var object = { x: 500 }; var arr = ["Nine", "Non", "Tape"]; console.log(typeof undef); //"undefined" console.log(typeof num); //"number" console.log(typeof str); //"string" console.log(typeof bool); //"boolean" console.log(typeof func); //"function" console.log(typeof object); // "object" console.log(typeof arr); // "object" //check object instance of class var arr = ["Nine", "Non", "Tape"]; console.log(arr instanceof Array); // true function Speaker() { this.name = "Nine"; } var mrNine = new Speaker(); console.log(mrNine instanceof Speaker); // true
  • 20. JavaScript Basic Programming Value of variables are always false in condition var a = null; var b; // undefined var c = 0; var d = false; var e = ""; if (a) // false if (b) // false if (c) // false if (d) // false if (e) // false
  • 21. JavaScript Basic Programming Inheritance with Prototype function Speaker(isSpeaking) { this.isSpeaking = isSpeaking == null ? false : isSpeaking; } Speaker.prototype.say = function () {return "Break session"; }; function ZZSpeaker () { this.isEating = true; } ZZSpeaker.prototype = new Speaker(); ZZSpeaker.prototype.sleepyShow = function () { alert('wake up !!!'); }; ZZSpeaker.prototype.say = function () { return "Ask me please.."; }; var nineSpeak = new ZZSpeaker(); nineSpeak.say(); nineSpeak.sleepyShow();
  • 22. 3rd JavaScript Framework and Library jQuery is a library created on top JavaScript, to help us access DOM and populate HTML element, content , CSS, animation and DOM Event The two thinks jQuery dose 1. SELECT elements or a group of element by CSS Selector 2. Take Action on elements
  • 23. 3rd JavaScript Framework and Library jQuery : Get Started <!DOCTYPE html> <html> <head> <title></title> </head> <body> <div class="test"></div> <!-- 1. Add script reference to local or CDN --> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script> //2. declare document ready $(document).ready(function () { $('div.test').html("<h1>JavaScript for web developer</h1>"); }); </script> </body> </html>
  • 24. 3rd JavaScript Framework and Library jQuery : query and action <div class="test"></div> <input id="btnShowMessage" type="button" value="click me" /> //2. declare document ready $(document).ready(function () { //3. Bind Element Action to custom function $('#btnShowMessage').click(function () { $('div.test').html("<h1>DOM Ready binding event</h1>"); }); }); //4. Early binding event can declare out of DOM Ready block $('#btnShowMessage').on('click', function () { $('div.test').html("<h1>Early binding event</h1>"); });
  • 28. AJAX: Asynchronous JavaScript and XML None blocking user action and no screen freeze
  • 29. Use AJAX (native code) // This is the client-side script // Initialize the Ajax request var xhr = XMLHttpRequest(); xhr.open('get', 'http://google.com'); // Track the state changes of the request xhr.onreadystatechange = function () { // Ready state 4 means the request is done if (xhr.readyState === 4) { // 200 is a successful return if (xhr.status === 200) { alert(xhr.responseText); // 'This is the returned text.' } else { alert('Error: ' + xhr.status); // An error occurred during the request } }} // Send the request to send-ajax-data.php xhr.send(null);
  • 30. Use AJAX with JQUERY $.get() $.post() $.getJSON() $.ajax() Demo $.get('ajax/test.html', function (data) { $('.result').html(data); alert('Load was performed.'); }); $.post('ajax/test.html', function (data) { $('.result').html(data); }); $.getJSON('ajax/test.json', function (data) { var items = []; $.each(data, function (key, val) { items.push('<li id="' + key + '">' + val + '</li>'); }); });
  • 33. JSON : JavaScript Object Notation JSON is a text-based open standard designed for human-readable data interchange //JavaScript Object var session = { name: 'Nine', sessionName: 'JavaScript for Web Developer', }; //JSON Object {"name": "Nine", "sessionName" : "JavaScript for Web Developer" }
  • 34. JSON JavaScript Object to JSON var session = { name: $('input#name').val(), sessionName: $('input#sesseionName').val() }; //convert to json var json = JSON.stringify(session);
  • 36. Debug JavaScript JavaScript Debugger Tools 1. Browser Web Developer Tools (F12) 2. Visual Studio 2012 + IE10 or later
  • 37. Debug JavaScript Put break point and click html button
  • 39. MVC power by AngularJS article