SlideShare une entreprise Scribd logo
1  sur  31
Copyright of http://it-corporate-trainer.prahalad-das.in 1
ADVANCE JAVA SCRIPT
TRAINING
Copyright of http://it-corporate-trainer.prahalad-das.in 2
JavaScript Basics
● Very Popular Language.
● Misunderstood programming language.
● Dynamic Scripting Language.
● Very few Language construct.
● OOPs and Functional programming support **
● Doesnt have Classes and Function are first
class Objects. *
● This is an advantage not deficiency
● Closure Support in Javascript for ages.
Copyright of http://it-corporate-trainer.prahalad-das.in 3
Reasons for Popularity
● V8 Engine run out side browser
● Node.js as server component
● Out of box functional programming.
● Very cool open source software available.
● Popularity of Single screen applications.
● Rhino jav8 support for java.
● Mobile platforms based on basic javascript.
Copyright of http://it-corporate-trainer.prahalad-das.in 4
JavaScript Objects
● Just 5 inbuilt objects
● null, undefined, String , number.
● Very few in built objects ( But not a drawback)
● Array , Date , etc.
● User defined objects can be defined.
● User defined objects can be persisted as JSON
● var variable_x = {}; // Basic Object.
● Add attributes to a black object.
● Gang of 4: perfect object composition 2 inheritance.
Copyright of http://it-corporate-trainer.prahalad-das.in 5
Console output
● View in Chrome – ctrl-shift-J
● console.log(“prahalad, Lord's Bhakt”);
● Takes variable argument
● console.log(“prahalad”,1{},
{“lastName”:“das”,“firstName”:“prahalad”});
● This will print all of them in one line.
● Console.dir( object ); this prints the whole
object neatly in seperate lines.
Copyright of http://it-corporate-trainer.prahalad-das.in 6
Prototype Step 1
● Inheritance in JS exists using Prototype.
● Every Function you create has a prototype property.
● This protype is an empty.
● Convention OOPS
● First create class then create objects.
● Protype is Copy Object.
● Because of prototype there is less number of code.
● Need more 2 discuss on this later slides.
Copyright of http://it-corporate-trainer.prahalad-das.in 7
eval is Evil
● Dynamic Instantiation have helped Languages
● Create framework.
● Extend and call classes that you dont know.
● THINK HOW TOMCAT instantiated your class
without even knowing about the class.
– By Class.forName in java
● But Eval does some thing similar.
● But javascript scope defination creates pain.
● Security concerns as the scope object could be
compromised.
Copyright of http://it-corporate-trainer.prahalad-das.in 8
Bug free Vs Speed
● Bugs are set back.
● Relook older code.
● Revist the requirement.
● Code changes have potential of breaking existing
functionality of the application.
● We will spend more time reading than writing.
● So create code by patterns that are understood
by the team.
● Unit testing is essential, it also helps in reading
code.
Copyright of http://it-corporate-trainer.prahalad-das.in 9
Minimize Global....how?
● In Java code starts from main method.
● JS code starts the first line, as we keep including
the js file it starts getting executed or recorded**
● Because of first pt, the application starts generating
global variables.
● Weird gobal variable names by framework.
● $ - is the global variable created by jquery
● _ - is the global variable created by underscore.js
● So there are good posibility that we would be
over writting the global variables.
Copyright of http://it-corporate-trainer.prahalad-das.in 10
Minimize global contd.
● Global object accessed by this **outside function.
● Global variables becomes attribute to top object. For JS in
browser it is “window”
_global_var = “prahalad”; //note var not used
console.log(window._global_var);
console.log(this._global_var);//logic reused outside windows.
● Pattern use var to declare.
function sumNumbers(x, y) {
result = x + y;//result is global can conflict, with third party or your own script.
return result;//BIG PROBLEM
}
var a1 = a2 = 0;//a1 is local a2 is global; instead use var a1,a2;
Copyright of http://it-corporate-trainer.prahalad-das.in 11
Global contd..
● Implied vs explicitly.
● Declared with “var” outside function explicit
global variable.
● Delete Object – Only applied to Implied object
only not for explicit objects.
●
“delete” operator in javascript.
delete a1;//deletes only implied objects not explicit objects.
● JUST NOTE: Strict mode can throw exception
var global = (function () {return this;}());//*declare+exec
Now “global” can now be used in browser and phonegap or
serverscripts application.
Copyright of http://it-corporate-trainer.prahalad-das.in 12
Global Contd..
● Two slides before we discussed how JS is
different from java(it starts from Main function)
● Here is an example.
global_greet = "HELLO"; // global variable
function func() {
alert(global_greet); // "undefined" as in this scope global_var was in local scope
var global_greet="Namaste";
//NOTE :Scope is pushed forward at start of function
alert(global_greet); // local scoped kicked in
}
Func( );//creates own scope
Javascript execution happens sequentially unlike Java.***
Copyright of http://it-corporate-trainer.prahalad-das.in 13
Basic Language Constructs
● For Loop While loop remains same as other languages.
● “for-in” - prefered to iterate on Object.
var house = {toilet: 2,bedRoom: 2,kitchen: 1,balcony=1,livingRoom=1,tvRoom=2};
for(var room in house){ console.log( room );}
● We can add function and variable on fly in javascript.***
● So assume we added will it show original object or the prototype object.
● Interesting thing about JS vs Java & C++
● In java you cant change behaviour of object while it is running.
● So transformer(movie) type CARS are never possible in java.
– Very much possible in JS.
– Possible in java to some degree by SPRING or Dynamic-PROXY.
● house.hasOwnProperty( room ) can check if it was manipulated.
Copyright of http://it-corporate-trainer.prahalad-das.in 14
Basic Language Constructs
● Appending functionality across all objects.
Refer & Explain Example – basic_prototype_all_objects.html
● Now you can append all the objects in the memory specific function.
● For example we want to add specific aspect or functionality across all
Objects.
● For example : Clone, persistance etc cross object functionality.
● Inheritance in Java & C++
● In java & C++ world we create class human and then create instance.
● Then common functionality of human becomes static variable.
● Inheritance in javascript.
● It is a true copy of single object.
● It is something like we all copied from Adam Or Eve.
● This basic difference between how JAVA/C++/.net world differ from JS world.
Copyright of http://it-corporate-trainer.prahalad-das.in 15
Prototype can be dangerous
● We have seen that it effects all objects.
● Can potentially change all inbuilt object.
if (typeof Object.prototype.overideFunction!== "function") {
//checking if we are overriding existing functionality
Object.protoype.overideFunction = function () {
// implementation...
};
}
● Now the above change we have a potential that
we dont know which all object have changed.
Copyright of http://it-corporate-trainer.prahalad-das.in 16
Change an Object at fly
● Blacket change is bad how @ specific change.
function employee(eName,title,dob){
this.eName=eName;
this.title=title;
this.dob=dob;
}
var nmurthy=new employee("N.Murthy","Mentor",1750);
employee.prototype.salary=null;//no hoisting for this.
nmurthy.salary=1;
var prince =new employee("Rajkumar","CEO in Making",1973);
console.dir(nmurthy);console.dir(price);
Copyright of http://it-corporate-trainer.prahalad-das.in 17
Ctnd...
● Change objects at fly.
● How we added salary variable to the employee
class.
● We can remove the salary function.
● No hoisting happens for this, as scope
happens.( price_ceo.html *** )
● We can add function to an object.
● Now when compared this to more statically
typed language it is a great advantange.
Copyright of http://it-corporate-trainer.prahalad-das.in 18
Hoisting
● Hoisting becomes complex
function firstFunction() {alert('global firstFunction');};
function secondFunction() {alert('global secondFunction2');};
function hoistingIssue() {
console.log(typeof secondFunction); console.log(typeof firstFunction);
secondFunction(); //firstFunction(); //will fail
function secondFunction() {alert('local secondFunction');}//function hoisting
var firstFunction = function () { alert('local firstFunction'); };//variable hoisting blank
FirstFunction();//now it works, variable is posted with function type
}
hoistingIssue();//hoisting of local variable begins.
Copyright of http://it-corporate-trainer.prahalad-das.in 19
Implied Type Casting
● false==0 -- true
● “XYZ”==true -- true
● false===0 --false
● Checks data type.
● Then compared value.
● Not check reference.
● Do you know you can return undefined
● Very useful most of the language dont have this feature
function canReturnUndefined(){return undefined;// keyword }
Copyright of http://it-corporate-trainer.prahalad-das.in 20
Tools & Convention
● Function called with new acts as constructor.
● Class starts with first letter CAPITAL.
● Private variable and private function starts with
underscore.
● Note all these are not mandatory but a convension
of this industry.
● Jsdoc most used to create js documentation of
the API.
● Comment annotation used to create jsdoc.
● Google closurer tool to mimify
Copyright of http://it-corporate-trainer.prahalad-das.in 21
Dynamic Language
● Most of the dynamic languages supports
simplified object constructor.
● They hold attribute and function as attributes of
hashmap.
● You can add attributes after the object is
constructed.
var pet = {};// add one property
pet.name = "Pottu";// now add a method
pet.getName = function () {return pet.name;};
We added attribute to my pet after it was created.
delete dog.name;
Copyright of http://it-corporate-trainer.prahalad-das.in 22
JavaScript Literals
● Above example literal object “json”
var pet = {
name: "Pottu", //literal seperator is,
getName: function () { return this.name; }
};
● Above object can be passed to any other
languages could also be converted to
respective languages Object.
● For example – gson for java.
● Few built-in constructor number(),Date(),String(),Object()
Copyright of http://it-corporate-trainer.prahalad-das.in 23
JSon
● Literal presentation of object.
● Persisted and passed around network and
database (mangoDB/clob rows).
var data = JSON.parse(jstr);//objects get created
● So network application can pass object state in
string format.
var jsonstr = JSON.stringify(dog);
● We can get string persistable state of an
Object.
Copyright of http://it-corporate-trainer.prahalad-das.in 24
Similar to classes
● Pay attention to RED color keyword in code.
var Person = function (name) {
//implicit call var this={}
this.name = name;
this.say = function () {//why implicit this was not created here and effected this?
return "I am " + this.name;
};
//return this;//implicits
};
● Note “this” outside a function scope refers to global object
like window or phonegap objects.
Copyright of http://it-corporate-trainer.prahalad-das.in 25
JavaScript Constructor
● A function can be called with or with out new
● When called with new returns Object “this”.
● When called without new it executes function.
● This is very important concept to grab.CONSTRUCTOR.html***
● When created with new it creates __proto__ attribute to understand if it was
a function or an object from console.
function human(name){//this={}; implicit
this.name = name;
this.introduceHuman=function (){return "HI i am "+this.name;}}//return
this;
var nonNewPrahalad = human("Prahalad"); var newPrahalad = new
human("Prahalad");console.dir( newPrahalad );console.dir( nonNewPrahala
d );//returns undefined.
human.prototype.sayBye = function () {return "Bye Bye" ;};//add attr&Function
Copyright of http://it-corporate-trainer.prahalad-das.in 26
Constructors and Convention
● Constructor if not used with convention can be disaster, if not use properly
you will spend days debugging it SO PLEASE PAY ATTENTION.
● Project success has hundred fathers, for failed javascript project have a
single father “Developer who dont understand this slide” ( JOKE ).
Assume we have a global variable name in the above example.
name = "God";//global variable
function Human(name){//check the function with capital letter(so Class)
this.name = name;//change global variable
this.introduceHuman=function (){ return "HI i am "+this.name;}
}
Human(“prahalad”);//this will change global variable.(note: new operator not
used)
console.log("Told u to use new operator, so god is now : "+ name);
Copyright of http://it-corporate-trainer.prahalad-das.in 27
Avoid Problem with that
function Human(name) {
var that = {};
that.name = name;
that.introduce= function(){
return “Hey my name”+that.name;
}
return that;
}//GOOD PATTERN MUST FOLLOW THIS
● That helped me a lot as what ever i write i would not
cpawanPutrahange the global variable.
● So my code remains safe.
● “that” is not a key word – name convention
Copyright of http://it-corporate-trainer.prahalad-das.in 28
Force Function call 2 Constructor
● We can force function call to constructor call.
● “instanceof” operator does work to check if they used constructor.
function Human(name){
if ( !(this instanceof Human) ) {
return new Human(); // trick is here
}//another better way is = new arguments.callee( ) ** bit advance concept.
this.name...//code not completed
}
var instance = Human(“prahalad”);
● You always create object inspite of not using new operator. Good for API
developers.
Copyright of http://it-corporate-trainer.prahalad-das.in 29
Call Backs!!
● All major framework use this concept.
● You dont call me I will you, when time and scenario
arrive.
● Servlet Container call your Servlet in JAVA.
● So how call back in java
function i_will_call_you_Back(registered_callback) {
// can do something...
registered_callback();//can check if it is a “function” before you fire it.
// post call back operation like reply object handling
}
Copyright of http://it-corporate-trainer.prahalad-das.in 30
Paid Training
● Contact http://it-corporate-trainer.prahalad-das.in
● Note this is a paid Training.
● This slide is just to show case our depth of understanding in this subject.
● It is a complete 3 days training.
● Training includes training handout(hardcopy), worksheet & practice
examples also.
Copyright of http://it-corporate-trainer.prahalad-das.in 31

Contenu connexe

Tendances

The Gist of React Native
The Gist of React NativeThe Gist of React Native
The Gist of React NativeDarren Cruse
 
Js fwdays unit tesing javascript(by Anna Khabibullina)
Js fwdays unit tesing javascript(by Anna Khabibullina)Js fwdays unit tesing javascript(by Anna Khabibullina)
Js fwdays unit tesing javascript(by Anna Khabibullina)Anna Khabibullina
 
JS Frameworks Day April,26 of 2014
JS Frameworks Day April,26 of 2014JS Frameworks Day April,26 of 2014
JS Frameworks Day April,26 of 2014DA-14
 
Adobe Flex Component Lifecycle
Adobe Flex Component LifecycleAdobe Flex Component Lifecycle
Adobe Flex Component LifecycleRJ Owen
 
Java and Java platforms
Java and Java platformsJava and Java platforms
Java and Java platformsIlio Catallo
 
Григорий Шехет "Treasure hunt in the land of Reactive frameworks"
Григорий Шехет "Treasure hunt in the land of Reactive frameworks"Григорий Шехет "Treasure hunt in the land of Reactive frameworks"
Григорий Шехет "Treasure hunt in the land of Reactive frameworks"Fwdays
 
Intro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiIntro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiRan Mizrahi
 
Functional Reactive Programming in the Netflix API
Functional Reactive Programming in the Netflix APIFunctional Reactive Programming in the Netflix API
Functional Reactive Programming in the Netflix APIC4Media
 
Application Development Using Java - DIYComputerScience Course
Application Development Using Java - DIYComputerScience CourseApplication Development Using Java - DIYComputerScience Course
Application Development Using Java - DIYComputerScience Courseparag
 
Intro to JavaScript Testing
Intro to JavaScript TestingIntro to JavaScript Testing
Intro to JavaScript TestingRan Mizrahi
 
Behat Workshop at WeLovePHP
Behat Workshop at WeLovePHPBehat Workshop at WeLovePHP
Behat Workshop at WeLovePHPMarcos Quesada
 
Java Concurrency and Asynchronous
Java Concurrency and AsynchronousJava Concurrency and Asynchronous
Java Concurrency and AsynchronousLifan Yang
 
Introduction to Java
Introduction to Java Introduction to Java
Introduction to Java Hitesh-Java
 
Making React Native UI Components with Swift
Making React Native UI Components with SwiftMaking React Native UI Components with Swift
Making React Native UI Components with SwiftRay Deck
 

Tendances (20)

The Gist of React Native
The Gist of React NativeThe Gist of React Native
The Gist of React Native
 
Java introduction
Java introductionJava introduction
Java introduction
 
ClassJS
ClassJSClassJS
ClassJS
 
React
React React
React
 
Js fwdays unit tesing javascript(by Anna Khabibullina)
Js fwdays unit tesing javascript(by Anna Khabibullina)Js fwdays unit tesing javascript(by Anna Khabibullina)
Js fwdays unit tesing javascript(by Anna Khabibullina)
 
JS Frameworks Day April,26 of 2014
JS Frameworks Day April,26 of 2014JS Frameworks Day April,26 of 2014
JS Frameworks Day April,26 of 2014
 
Adobe Flex Component Lifecycle
Adobe Flex Component LifecycleAdobe Flex Component Lifecycle
Adobe Flex Component Lifecycle
 
Java and Java platforms
Java and Java platformsJava and Java platforms
Java and Java platforms
 
Григорий Шехет "Treasure hunt in the land of Reactive frameworks"
Григорий Шехет "Treasure hunt in the land of Reactive frameworks"Григорий Шехет "Treasure hunt in the land of Reactive frameworks"
Григорий Шехет "Treasure hunt in the land of Reactive frameworks"
 
Intro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiIntro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran Mizrahi
 
Functional Reactive Programming in the Netflix API
Functional Reactive Programming in the Netflix APIFunctional Reactive Programming in the Netflix API
Functional Reactive Programming in the Netflix API
 
Application Development Using Java - DIYComputerScience Course
Application Development Using Java - DIYComputerScience CourseApplication Development Using Java - DIYComputerScience Course
Application Development Using Java - DIYComputerScience Course
 
All of Javascript
All of JavascriptAll of Javascript
All of Javascript
 
Test your modules
Test your modulesTest your modules
Test your modules
 
Intro to JavaScript Testing
Intro to JavaScript TestingIntro to JavaScript Testing
Intro to JavaScript Testing
 
Behat Workshop at WeLovePHP
Behat Workshop at WeLovePHPBehat Workshop at WeLovePHP
Behat Workshop at WeLovePHP
 
Unit Testing in AngularJS - CC FE & UX
Unit Testing in AngularJS -  CC FE & UXUnit Testing in AngularJS -  CC FE & UX
Unit Testing in AngularJS - CC FE & UX
 
Java Concurrency and Asynchronous
Java Concurrency and AsynchronousJava Concurrency and Asynchronous
Java Concurrency and Asynchronous
 
Introduction to Java
Introduction to Java Introduction to Java
Introduction to Java
 
Making React Native UI Components with Swift
Making React Native UI Components with SwiftMaking React Native UI Components with Swift
Making React Native UI Components with Swift
 

En vedette

JavaScripters Event Sep 17, 2016 · 2:00 PM: Scalable Javascript Design Patterns
JavaScripters Event Sep 17, 2016 · 2:00 PM: Scalable Javascript Design PatternsJavaScripters Event Sep 17, 2016 · 2:00 PM: Scalable Javascript Design Patterns
JavaScripters Event Sep 17, 2016 · 2:00 PM: Scalable Javascript Design PatternsJavaScripters Community
 
Advance j sinhindi
Advance j sinhindiAdvance j sinhindi
Advance j sinhindiChand Rook
 
Advancing JavaScript with Libraries (Yahoo Tech Talk)
Advancing JavaScript with Libraries (Yahoo Tech Talk)Advancing JavaScript with Libraries (Yahoo Tech Talk)
Advancing JavaScript with Libraries (Yahoo Tech Talk)jeresig
 
Good Parts of JavaScript Douglas Crockford
Good Parts of JavaScript Douglas CrockfordGood Parts of JavaScript Douglas Crockford
Good Parts of JavaScript Douglas Crockfordrajivmordani
 
GeoLocation using Google Maps JavaScript API v3
GeoLocation using Google Maps JavaScript API v3GeoLocation using Google Maps JavaScript API v3
GeoLocation using Google Maps JavaScript API v3S M Mohi Us Sunnat
 
Javascript Tutorial
Javascript TutorialJavascript Tutorial
Javascript TutorialKang-min Liu
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An IntroductionManvendra Singh
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Languageguestceb98b
 
Scalable JavaScript Application Architecture
Scalable JavaScript Application ArchitectureScalable JavaScript Application Architecture
Scalable JavaScript Application ArchitectureNicholas Zakas
 

En vedette (11)

JavaScripters Event Sep 17, 2016 · 2:00 PM: Scalable Javascript Design Patterns
JavaScripters Event Sep 17, 2016 · 2:00 PM: Scalable Javascript Design PatternsJavaScripters Event Sep 17, 2016 · 2:00 PM: Scalable Javascript Design Patterns
JavaScripters Event Sep 17, 2016 · 2:00 PM: Scalable Javascript Design Patterns
 
Advance j sinhindi
Advance j sinhindiAdvance j sinhindi
Advance j sinhindi
 
Debugging with Firebug
Debugging with Firebug Debugging with Firebug
Debugging with Firebug
 
Advancing JavaScript with Libraries (Yahoo Tech Talk)
Advancing JavaScript with Libraries (Yahoo Tech Talk)Advancing JavaScript with Libraries (Yahoo Tech Talk)
Advancing JavaScript with Libraries (Yahoo Tech Talk)
 
Good Parts of JavaScript Douglas Crockford
Good Parts of JavaScript Douglas CrockfordGood Parts of JavaScript Douglas Crockford
Good Parts of JavaScript Douglas Crockford
 
GeoLocation using Google Maps JavaScript API v3
GeoLocation using Google Maps JavaScript API v3GeoLocation using Google Maps JavaScript API v3
GeoLocation using Google Maps JavaScript API v3
 
Javascript Tutorial
Javascript TutorialJavascript Tutorial
Javascript Tutorial
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
 
Scalable JavaScript Application Architecture
Scalable JavaScript Application ArchitectureScalable JavaScript Application Architecture
Scalable JavaScript Application Architecture
 
Javascript Best Practices
Javascript Best PracticesJavascript Best Practices
Javascript Best Practices
 

Similaire à Javascript training sample

"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James NelsonGWTcon
 
Java Course 15: Ant, Scripting, Spring, Hibernate
Java Course 15: Ant, Scripting, Spring, HibernateJava Course 15: Ant, Scripting, Spring, Hibernate
Java Course 15: Ant, Scripting, Spring, HibernateAnton Keks
 
Batch Applications for the Java Platform
Batch Applications for the Java PlatformBatch Applications for the Java Platform
Batch Applications for the Java PlatformSivakumar Thyagarajan
 
LISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial HandoutsLISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial HandoutsTobias Oetiker
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingHoat Le
 
Exploring Kotlin language basics for Android App development
Exploring Kotlin language basics for Android App developmentExploring Kotlin language basics for Android App development
Exploring Kotlin language basics for Android App developmentJayaprakash R
 
Developing cross platform desktop application with Ruby
Developing cross platform desktop application with RubyDeveloping cross platform desktop application with Ruby
Developing cross platform desktop application with RubyAnis Ahmad
 
node.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoonnode.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang YoonJesang Yoon
 
Intro to Flutter
Intro to FlutterIntro to Flutter
Intro to FlutterEason Pai
 
The Power of the JVM: Applied Polyglot Projects with Java and JavaScript
The Power of the JVM: Applied Polyglot Projects with Java and JavaScriptThe Power of the JVM: Applied Polyglot Projects with Java and JavaScript
The Power of the JVM: Applied Polyglot Projects with Java and JavaScriptHazelcast
 
The State of the Veil Framework
The State of the Veil FrameworkThe State of the Veil Framework
The State of the Veil FrameworkVeilFramework
 
Java 9 features
Java 9 featuresJava 9 features
Java 9 featuresshrinath97
 
Java/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCJava/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCFAKHRUN NISHA
 
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...Codemotion
 
Best practices for ansible
Best practices for ansibleBest practices for ansible
Best practices for ansibleGeorge Shuklin
 
Deep dive into Android async operations
Deep dive into Android async operationsDeep dive into Android async operations
Deep dive into Android async operationsMateusz Grzechociński
 

Similaire à Javascript training sample (20)

"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson
 
Java Course 15: Ant, Scripting, Spring, Hibernate
Java Course 15: Ant, Scripting, Spring, HibernateJava Course 15: Ant, Scripting, Spring, Hibernate
Java Course 15: Ant, Scripting, Spring, Hibernate
 
Java 10 - Key Note
Java 10 - Key NoteJava 10 - Key Note
Java 10 - Key Note
 
Batch Applications for the Java Platform
Batch Applications for the Java PlatformBatch Applications for the Java Platform
Batch Applications for the Java Platform
 
LISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial HandoutsLISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial Handouts
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction Training
 
Exploring Kotlin language basics for Android App development
Exploring Kotlin language basics for Android App developmentExploring Kotlin language basics for Android App development
Exploring Kotlin language basics for Android App development
 
Developing cross platform desktop application with Ruby
Developing cross platform desktop application with RubyDeveloping cross platform desktop application with Ruby
Developing cross platform desktop application with Ruby
 
Java 9 Features
Java 9 FeaturesJava 9 Features
Java 9 Features
 
node.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoonnode.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoon
 
Intro to Flutter
Intro to FlutterIntro to Flutter
Intro to Flutter
 
The Power of the JVM: Applied Polyglot Projects with Java and JavaScript
The Power of the JVM: Applied Polyglot Projects with Java and JavaScriptThe Power of the JVM: Applied Polyglot Projects with Java and JavaScript
The Power of the JVM: Applied Polyglot Projects with Java and JavaScript
 
The State of the Veil Framework
The State of the Veil FrameworkThe State of the Veil Framework
The State of the Veil Framework
 
Java 9 features
Java 9 featuresJava 9 features
Java 9 features
 
JavaScript-Core
JavaScript-CoreJavaScript-Core
JavaScript-Core
 
JavaScript-Core
JavaScript-CoreJavaScript-Core
JavaScript-Core
 
Java/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCJava/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBC
 
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
 
Best practices for ansible
Best practices for ansibleBest practices for ansible
Best practices for ansible
 
Deep dive into Android async operations
Deep dive into Android async operationsDeep dive into Android async operations
Deep dive into Android async operations
 

Dernier

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 

Dernier (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 

Javascript training sample

  • 2. Copyright of http://it-corporate-trainer.prahalad-das.in 2 JavaScript Basics ● Very Popular Language. ● Misunderstood programming language. ● Dynamic Scripting Language. ● Very few Language construct. ● OOPs and Functional programming support ** ● Doesnt have Classes and Function are first class Objects. * ● This is an advantage not deficiency ● Closure Support in Javascript for ages.
  • 3. Copyright of http://it-corporate-trainer.prahalad-das.in 3 Reasons for Popularity ● V8 Engine run out side browser ● Node.js as server component ● Out of box functional programming. ● Very cool open source software available. ● Popularity of Single screen applications. ● Rhino jav8 support for java. ● Mobile platforms based on basic javascript.
  • 4. Copyright of http://it-corporate-trainer.prahalad-das.in 4 JavaScript Objects ● Just 5 inbuilt objects ● null, undefined, String , number. ● Very few in built objects ( But not a drawback) ● Array , Date , etc. ● User defined objects can be defined. ● User defined objects can be persisted as JSON ● var variable_x = {}; // Basic Object. ● Add attributes to a black object. ● Gang of 4: perfect object composition 2 inheritance.
  • 5. Copyright of http://it-corporate-trainer.prahalad-das.in 5 Console output ● View in Chrome – ctrl-shift-J ● console.log(“prahalad, Lord's Bhakt”); ● Takes variable argument ● console.log(“prahalad”,1{}, {“lastName”:“das”,“firstName”:“prahalad”}); ● This will print all of them in one line. ● Console.dir( object ); this prints the whole object neatly in seperate lines.
  • 6. Copyright of http://it-corporate-trainer.prahalad-das.in 6 Prototype Step 1 ● Inheritance in JS exists using Prototype. ● Every Function you create has a prototype property. ● This protype is an empty. ● Convention OOPS ● First create class then create objects. ● Protype is Copy Object. ● Because of prototype there is less number of code. ● Need more 2 discuss on this later slides.
  • 7. Copyright of http://it-corporate-trainer.prahalad-das.in 7 eval is Evil ● Dynamic Instantiation have helped Languages ● Create framework. ● Extend and call classes that you dont know. ● THINK HOW TOMCAT instantiated your class without even knowing about the class. – By Class.forName in java ● But Eval does some thing similar. ● But javascript scope defination creates pain. ● Security concerns as the scope object could be compromised.
  • 8. Copyright of http://it-corporate-trainer.prahalad-das.in 8 Bug free Vs Speed ● Bugs are set back. ● Relook older code. ● Revist the requirement. ● Code changes have potential of breaking existing functionality of the application. ● We will spend more time reading than writing. ● So create code by patterns that are understood by the team. ● Unit testing is essential, it also helps in reading code.
  • 9. Copyright of http://it-corporate-trainer.prahalad-das.in 9 Minimize Global....how? ● In Java code starts from main method. ● JS code starts the first line, as we keep including the js file it starts getting executed or recorded** ● Because of first pt, the application starts generating global variables. ● Weird gobal variable names by framework. ● $ - is the global variable created by jquery ● _ - is the global variable created by underscore.js ● So there are good posibility that we would be over writting the global variables.
  • 10. Copyright of http://it-corporate-trainer.prahalad-das.in 10 Minimize global contd. ● Global object accessed by this **outside function. ● Global variables becomes attribute to top object. For JS in browser it is “window” _global_var = “prahalad”; //note var not used console.log(window._global_var); console.log(this._global_var);//logic reused outside windows. ● Pattern use var to declare. function sumNumbers(x, y) { result = x + y;//result is global can conflict, with third party or your own script. return result;//BIG PROBLEM } var a1 = a2 = 0;//a1 is local a2 is global; instead use var a1,a2;
  • 11. Copyright of http://it-corporate-trainer.prahalad-das.in 11 Global contd.. ● Implied vs explicitly. ● Declared with “var” outside function explicit global variable. ● Delete Object – Only applied to Implied object only not for explicit objects. ● “delete” operator in javascript. delete a1;//deletes only implied objects not explicit objects. ● JUST NOTE: Strict mode can throw exception var global = (function () {return this;}());//*declare+exec Now “global” can now be used in browser and phonegap or serverscripts application.
  • 12. Copyright of http://it-corporate-trainer.prahalad-das.in 12 Global Contd.. ● Two slides before we discussed how JS is different from java(it starts from Main function) ● Here is an example. global_greet = "HELLO"; // global variable function func() { alert(global_greet); // "undefined" as in this scope global_var was in local scope var global_greet="Namaste"; //NOTE :Scope is pushed forward at start of function alert(global_greet); // local scoped kicked in } Func( );//creates own scope Javascript execution happens sequentially unlike Java.***
  • 13. Copyright of http://it-corporate-trainer.prahalad-das.in 13 Basic Language Constructs ● For Loop While loop remains same as other languages. ● “for-in” - prefered to iterate on Object. var house = {toilet: 2,bedRoom: 2,kitchen: 1,balcony=1,livingRoom=1,tvRoom=2}; for(var room in house){ console.log( room );} ● We can add function and variable on fly in javascript.*** ● So assume we added will it show original object or the prototype object. ● Interesting thing about JS vs Java & C++ ● In java you cant change behaviour of object while it is running. ● So transformer(movie) type CARS are never possible in java. – Very much possible in JS. – Possible in java to some degree by SPRING or Dynamic-PROXY. ● house.hasOwnProperty( room ) can check if it was manipulated.
  • 14. Copyright of http://it-corporate-trainer.prahalad-das.in 14 Basic Language Constructs ● Appending functionality across all objects. Refer & Explain Example – basic_prototype_all_objects.html ● Now you can append all the objects in the memory specific function. ● For example we want to add specific aspect or functionality across all Objects. ● For example : Clone, persistance etc cross object functionality. ● Inheritance in Java & C++ ● In java & C++ world we create class human and then create instance. ● Then common functionality of human becomes static variable. ● Inheritance in javascript. ● It is a true copy of single object. ● It is something like we all copied from Adam Or Eve. ● This basic difference between how JAVA/C++/.net world differ from JS world.
  • 15. Copyright of http://it-corporate-trainer.prahalad-das.in 15 Prototype can be dangerous ● We have seen that it effects all objects. ● Can potentially change all inbuilt object. if (typeof Object.prototype.overideFunction!== "function") { //checking if we are overriding existing functionality Object.protoype.overideFunction = function () { // implementation... }; } ● Now the above change we have a potential that we dont know which all object have changed.
  • 16. Copyright of http://it-corporate-trainer.prahalad-das.in 16 Change an Object at fly ● Blacket change is bad how @ specific change. function employee(eName,title,dob){ this.eName=eName; this.title=title; this.dob=dob; } var nmurthy=new employee("N.Murthy","Mentor",1750); employee.prototype.salary=null;//no hoisting for this. nmurthy.salary=1; var prince =new employee("Rajkumar","CEO in Making",1973); console.dir(nmurthy);console.dir(price);
  • 17. Copyright of http://it-corporate-trainer.prahalad-das.in 17 Ctnd... ● Change objects at fly. ● How we added salary variable to the employee class. ● We can remove the salary function. ● No hoisting happens for this, as scope happens.( price_ceo.html *** ) ● We can add function to an object. ● Now when compared this to more statically typed language it is a great advantange.
  • 18. Copyright of http://it-corporate-trainer.prahalad-das.in 18 Hoisting ● Hoisting becomes complex function firstFunction() {alert('global firstFunction');}; function secondFunction() {alert('global secondFunction2');}; function hoistingIssue() { console.log(typeof secondFunction); console.log(typeof firstFunction); secondFunction(); //firstFunction(); //will fail function secondFunction() {alert('local secondFunction');}//function hoisting var firstFunction = function () { alert('local firstFunction'); };//variable hoisting blank FirstFunction();//now it works, variable is posted with function type } hoistingIssue();//hoisting of local variable begins.
  • 19. Copyright of http://it-corporate-trainer.prahalad-das.in 19 Implied Type Casting ● false==0 -- true ● “XYZ”==true -- true ● false===0 --false ● Checks data type. ● Then compared value. ● Not check reference. ● Do you know you can return undefined ● Very useful most of the language dont have this feature function canReturnUndefined(){return undefined;// keyword }
  • 20. Copyright of http://it-corporate-trainer.prahalad-das.in 20 Tools & Convention ● Function called with new acts as constructor. ● Class starts with first letter CAPITAL. ● Private variable and private function starts with underscore. ● Note all these are not mandatory but a convension of this industry. ● Jsdoc most used to create js documentation of the API. ● Comment annotation used to create jsdoc. ● Google closurer tool to mimify
  • 21. Copyright of http://it-corporate-trainer.prahalad-das.in 21 Dynamic Language ● Most of the dynamic languages supports simplified object constructor. ● They hold attribute and function as attributes of hashmap. ● You can add attributes after the object is constructed. var pet = {};// add one property pet.name = "Pottu";// now add a method pet.getName = function () {return pet.name;}; We added attribute to my pet after it was created. delete dog.name;
  • 22. Copyright of http://it-corporate-trainer.prahalad-das.in 22 JavaScript Literals ● Above example literal object “json” var pet = { name: "Pottu", //literal seperator is, getName: function () { return this.name; } }; ● Above object can be passed to any other languages could also be converted to respective languages Object. ● For example – gson for java. ● Few built-in constructor number(),Date(),String(),Object()
  • 23. Copyright of http://it-corporate-trainer.prahalad-das.in 23 JSon ● Literal presentation of object. ● Persisted and passed around network and database (mangoDB/clob rows). var data = JSON.parse(jstr);//objects get created ● So network application can pass object state in string format. var jsonstr = JSON.stringify(dog); ● We can get string persistable state of an Object.
  • 24. Copyright of http://it-corporate-trainer.prahalad-das.in 24 Similar to classes ● Pay attention to RED color keyword in code. var Person = function (name) { //implicit call var this={} this.name = name; this.say = function () {//why implicit this was not created here and effected this? return "I am " + this.name; }; //return this;//implicits }; ● Note “this” outside a function scope refers to global object like window or phonegap objects.
  • 25. Copyright of http://it-corporate-trainer.prahalad-das.in 25 JavaScript Constructor ● A function can be called with or with out new ● When called with new returns Object “this”. ● When called without new it executes function. ● This is very important concept to grab.CONSTRUCTOR.html*** ● When created with new it creates __proto__ attribute to understand if it was a function or an object from console. function human(name){//this={}; implicit this.name = name; this.introduceHuman=function (){return "HI i am "+this.name;}}//return this; var nonNewPrahalad = human("Prahalad"); var newPrahalad = new human("Prahalad");console.dir( newPrahalad );console.dir( nonNewPrahala d );//returns undefined. human.prototype.sayBye = function () {return "Bye Bye" ;};//add attr&Function
  • 26. Copyright of http://it-corporate-trainer.prahalad-das.in 26 Constructors and Convention ● Constructor if not used with convention can be disaster, if not use properly you will spend days debugging it SO PLEASE PAY ATTENTION. ● Project success has hundred fathers, for failed javascript project have a single father “Developer who dont understand this slide” ( JOKE ). Assume we have a global variable name in the above example. name = "God";//global variable function Human(name){//check the function with capital letter(so Class) this.name = name;//change global variable this.introduceHuman=function (){ return "HI i am "+this.name;} } Human(“prahalad”);//this will change global variable.(note: new operator not used) console.log("Told u to use new operator, so god is now : "+ name);
  • 27. Copyright of http://it-corporate-trainer.prahalad-das.in 27 Avoid Problem with that function Human(name) { var that = {}; that.name = name; that.introduce= function(){ return “Hey my name”+that.name; } return that; }//GOOD PATTERN MUST FOLLOW THIS ● That helped me a lot as what ever i write i would not cpawanPutrahange the global variable. ● So my code remains safe. ● “that” is not a key word – name convention
  • 28. Copyright of http://it-corporate-trainer.prahalad-das.in 28 Force Function call 2 Constructor ● We can force function call to constructor call. ● “instanceof” operator does work to check if they used constructor. function Human(name){ if ( !(this instanceof Human) ) { return new Human(); // trick is here }//another better way is = new arguments.callee( ) ** bit advance concept. this.name...//code not completed } var instance = Human(“prahalad”); ● You always create object inspite of not using new operator. Good for API developers.
  • 29. Copyright of http://it-corporate-trainer.prahalad-das.in 29 Call Backs!! ● All major framework use this concept. ● You dont call me I will you, when time and scenario arrive. ● Servlet Container call your Servlet in JAVA. ● So how call back in java function i_will_call_you_Back(registered_callback) { // can do something... registered_callback();//can check if it is a “function” before you fire it. // post call back operation like reply object handling }
  • 30. Copyright of http://it-corporate-trainer.prahalad-das.in 30 Paid Training ● Contact http://it-corporate-trainer.prahalad-das.in ● Note this is a paid Training. ● This slide is just to show case our depth of understanding in this subject. ● It is a complete 3 days training. ● Training includes training handout(hardcopy), worksheet & practice examples also.

Notes de l'éditeur

  1. Very age old language People assume it is similar to Java but it is not we will explain more in detail about this. Var that compiled time checked variables. So dynamic scripting. Number ,String , Object, null,undefined, boolean No int float double and other complex just 5 of them. Functions are Objects they can be passed. So delayed operation and state change. Passing function helps in creating DSL will talk later in depth. Object oriented with out creating classes, there is some unlearning that is needed which we will provide in our slides below. Annonymous Classes, JavaSwing are full of them but here in javascript programming it is back bone for good programming.
  2. V8 scripting engine moved the javascript running environment out of browsers. Node js is like apache seerver which can render server scripts with Reflection in java – can be run through for-in loop.
  3. function func() { varglobal_greet // same as -> var global_greet = undefined; alert( global_greet ); // "undefined" global_greet = "local"; alert( global_greet ); // "local" } //known as hoisting of variables, so it is a good practice to declare before than declaring any where when needed.