SlideShare a Scribd company logo
1 of 22
Javascript
04.02.2015. KZ.
What we won’t cover
1. Basics
2. Creating and using variables
3. Funcitons
4. Conditional statements
5. Loops
6. ……...
What we will cover
1. Scope
2. SAF (self-invoking anonymous functions)
3. Closures
4. Classes and objects
Scope
Scope is an area of variable visibility. Most
global scope is window object.
You can use defined variable in lower scopes,
but you can’t use it in upper scope.
Scope
1. var word = "Scandiweb",
2. output = function() {
3. console.log(word);
4. };
5.
6. output();
This is an example of upper scope variable inheritance. This will output to
console “Scandiweb” string, as expected.
Scope
1. var word = "Scandiweb",
2. output = function() {
3. var word = "Scandi";
4. console.log(word);
5. };
6.
7. output();
Lower scope variables will always take precedence over upper ones.
So, in this case “Scandi” will be outputted to the console.
Scope
Why this is important?
SAF
SAF has no difference from other functions,
except it launches itself.
(function(){
// code goes here
})();
// Other way to write it
function() {
// code goes here
}.call();
SAF
It is possible to pass any amount of arguments
to this functions, as for usual function.
1. (function($, doc, win, undef){
2. // jQuery is now available with $
3. })(jQuery, document, window);
SAF
Why SAF should be used?
Closures
1. var sayHello = (function() {
2. var firstWord = 'Hello, ';
3. return function(name) {
4. return firstWord + name + '!';
5. }
6. })();
7.
8. alert(sayHello('Scandiweb')); // Hello, Scandiweb!
9. alert(sayHello('Antons')); // Hello, Antons!
Why this works this way?
Closures
1. var linksArray = document.getElementsByTagName('a');
2.
3. for (var i = 0; i < 3; i++) {
4. linksArray[i].onclick = function() {
5. console.log(i);
6. }
7. }
Considering, we have three links (<a> tags) on page, and
on click we want to get link index, what is wrong with this
piece of code?
Closures
Right way to do it:
1. var linksArray = document.getElementsByTagName('a');
2.
3. for (var i = 0; i < 3; i++) {
4. linksArray[i].onclick = (function(count) {
5. return function() {
6. alert(count);
7. }
8. })(i);
9. }
Closures
So what?
Objects
So, we all know what is an object, right?
1. var object = {
2. 'foo': 'bar',
3. 'baz': [
4. 'foo',
5. 'bar'
6. ]
7. };
Here is a simple object, containing two elements.
Classes
To make things a bit simplier, let say this: any class in JS basically is a
function. At least, up until now - seems like real OOP is coming up in
ECMAScript 6.
So, lets try to write our own “Class.create()”!
Objects
1. var foo = Class.create({
2. initialize: function() {
3. // code here
4. },
5. someOtherFunction: function() {
6. // code here
7. }
8. });
9.
10. // Or, we even can do this
11. var bar = Class.create({});
12. bar.prototype.initalize = function() {
13. // code here
14. }
Classes
1. // Our class creator
2. var Class = {
3. create: function(methods) {
4. function instance() {
5. // Call our contructor function
6. this.start.apply(this, arguments);
7. };
8. for (key in methods) { // Extend our instance with passed methods
9. if (methods.hasOwnProperty(key)) {
10. instance.prototype[key] = methods[key];
11. }
12. }
13. return instance;
14. }
15. };
Classes
1. var speakerClass = Class.create({
2. start: function(name) {
3. this.name = name;
4. },
5. sayHiToSpeaker: function() {
6. return 'Hello, ' + this.name + '!';
7. }
8. });
9. var speakerObject1 = new speakerClass('John'),
10. speakerObject2 = new speakerClass('Joe');
11. speakerClass.prototype.smile = function() {
12. return this.name + ' smiles :)';
13. };
Classes
1. console.log(speakerObject1.sayHiToSpeaker()); // Hello, John!
2. console.log(speakerObject2.sayHiToSpeaker()); // Hello, Joe!
3.
4. console.log(speakerObject1.smile()); // John smiles :)
5. console.log(speakerObject2.smile()); // Joe smiles :)
Javascript
Questions?
Javascript
Thank u ;)

More Related Content

What's hot

JavaScript 101 - Class 1
JavaScript 101 - Class 1JavaScript 101 - Class 1
JavaScript 101 - Class 1Robert Pearce
 
JavaScript Conditional Statements
JavaScript Conditional StatementsJavaScript Conditional Statements
JavaScript Conditional StatementsMarlon Jamera
 
Understanding Asynchronous JavaScript
Understanding Asynchronous JavaScriptUnderstanding Asynchronous JavaScript
Understanding Asynchronous JavaScriptjnewmanux
 
Javascript basics for automation testing
Javascript  basics for automation testingJavascript  basics for automation testing
Javascript basics for automation testingVikas Thange
 
JavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UXJavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UXJWORKS powered by Ordina
 
Javascript: the important bits
Javascript: the important bitsJavascript: the important bits
Javascript: the important bitsChris Saylor
 
5 Tips for Better JavaScript
5 Tips for Better JavaScript5 Tips for Better JavaScript
5 Tips for Better JavaScriptTodd Anglin
 
JavaScript 101
JavaScript 101JavaScript 101
JavaScript 101ygv2000
 
Hardened JavaScript
Hardened JavaScriptHardened JavaScript
Hardened JavaScriptKrisKowal2
 
JavaScript Loop: Optimization of Weak Typing
JavaScript Loop: Optimization of Weak TypingJavaScript Loop: Optimization of Weak Typing
JavaScript Loop: Optimization of Weak TypingJanlay Wu
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionDmitry Sheiko
 
Getting Comfortable with JS Promises
Getting Comfortable with JS PromisesGetting Comfortable with JS Promises
Getting Comfortable with JS PromisesAsa Kusuma
 
Intro to Javascript
Intro to JavascriptIntro to Javascript
Intro to JavascriptAnjan Banda
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Domenic Denicola
 
The Ring programming language version 1.6 book - Part 77 of 189
The Ring programming language version 1.6 book - Part 77 of 189The Ring programming language version 1.6 book - Part 77 of 189
The Ring programming language version 1.6 book - Part 77 of 189Mahmoud Samir Fayed
 
JavaScript - From Birth To Closure
JavaScript - From Birth To ClosureJavaScript - From Birth To Closure
JavaScript - From Birth To ClosureRobert Nyman
 

What's hot (20)

JavaScript 101 - Class 1
JavaScript 101 - Class 1JavaScript 101 - Class 1
JavaScript 101 - Class 1
 
JavaScript Conditional Statements
JavaScript Conditional StatementsJavaScript Conditional Statements
JavaScript Conditional Statements
 
Understanding Asynchronous JavaScript
Understanding Asynchronous JavaScriptUnderstanding Asynchronous JavaScript
Understanding Asynchronous JavaScript
 
Javascript basics for automation testing
Javascript  basics for automation testingJavascript  basics for automation testing
Javascript basics for automation testing
 
JavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UXJavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UX
 
Javascript: the important bits
Javascript: the important bitsJavascript: the important bits
Javascript: the important bits
 
5 Tips for Better JavaScript
5 Tips for Better JavaScript5 Tips for Better JavaScript
5 Tips for Better JavaScript
 
Ggug spock
Ggug spockGgug spock
Ggug spock
 
JavaScript 101
JavaScript 101JavaScript 101
JavaScript 101
 
Hardened JavaScript
Hardened JavaScriptHardened JavaScript
Hardened JavaScript
 
JavaScript Loop: Optimization of Weak Typing
JavaScript Loop: Optimization of Weak TypingJavaScript Loop: Optimization of Weak Typing
JavaScript Loop: Optimization of Weak Typing
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Getting Comfortable with JS Promises
Getting Comfortable with JS PromisesGetting Comfortable with JS Promises
Getting Comfortable with JS Promises
 
Javascript
JavascriptJavascript
Javascript
 
Calling functions
Calling functionsCalling functions
Calling functions
 
Intro to Javascript
Intro to JavascriptIntro to Javascript
Intro to Javascript
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
 
Lesson16
Lesson16Lesson16
Lesson16
 
The Ring programming language version 1.6 book - Part 77 of 189
The Ring programming language version 1.6 book - Part 77 of 189The Ring programming language version 1.6 book - Part 77 of 189
The Ring programming language version 1.6 book - Part 77 of 189
 
JavaScript - From Birth To Closure
JavaScript - From Birth To ClosureJavaScript - From Birth To Closure
JavaScript - From Birth To Closure
 

Viewers also liked

Meteor intro-2015
Meteor intro-2015Meteor intro-2015
Meteor intro-2015MeteorJS
 
Meteor presentation
Meteor presentationMeteor presentation
Meteor presentationscandiweb
 
Voice Control Home Automation
Voice Control Home AutomationVoice Control Home Automation
Voice Control Home AutomationAbhishek Neb
 
3 d – printing
3 d – printing3 d – printing
3 d – printingGourav Pal
 
Scrum 101: Introduction to Scrum
Scrum 101: Introduction to ScrumScrum 101: Introduction to Scrum
Scrum 101: Introduction to ScrumArrielle Mali
 
Introduction to Scrum.ppt
Introduction to Scrum.pptIntroduction to Scrum.ppt
Introduction to Scrum.pptMohan Late
 
Scrum process powerpoint ppt slides.
Scrum process powerpoint ppt slides.Scrum process powerpoint ppt slides.
Scrum process powerpoint ppt slides.SlideTeam.net
 
3d printing technology
3d printing technology3d printing technology
3d printing technologyPrachi Agarwal
 
3D printer Technology _ A complete presentation
3D printer Technology _ A complete presentation3D printer Technology _ A complete presentation
3D printer Technology _ A complete presentationVijay Patil
 
Home automation ppt-kamal lamichhane
Home automation ppt-kamal lamichhaneHome automation ppt-kamal lamichhane
Home automation ppt-kamal lamichhaneKamal Lamichhane
 
Overview of Agile Methodology
Overview of Agile MethodologyOverview of Agile Methodology
Overview of Agile MethodologyHaresh Karkar
 
Home automation using android mobiles
Home automation using android mobilesHome automation using android mobiles
Home automation using android mobilesDurairaja
 
Google glass glasses presentation ppt
Google glass glasses presentation pptGoogle glass glasses presentation ppt
Google glass glasses presentation pptParth Godhani
 
2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShare2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShareSlideShare
 

Viewers also liked (20)

Meteor intro-2015
Meteor intro-2015Meteor intro-2015
Meteor intro-2015
 
Meteor presentation
Meteor presentationMeteor presentation
Meteor presentation
 
Understanding meteor
Understanding meteorUnderstanding meteor
Understanding meteor
 
Voice Control Home Automation
Voice Control Home AutomationVoice Control Home Automation
Voice Control Home Automation
 
3 d – printing
3 d – printing3 d – printing
3 d – printing
 
google glass
google glassgoogle glass
google glass
 
Scrum 101: Introduction to Scrum
Scrum 101: Introduction to ScrumScrum 101: Introduction to Scrum
Scrum 101: Introduction to Scrum
 
3 d printing
3 d printing 3 d printing
3 d printing
 
Introduction to Scrum.ppt
Introduction to Scrum.pptIntroduction to Scrum.ppt
Introduction to Scrum.ppt
 
Scrum process powerpoint ppt slides.
Scrum process powerpoint ppt slides.Scrum process powerpoint ppt slides.
Scrum process powerpoint ppt slides.
 
3d printing technology
3d printing technology3d printing technology
3d printing technology
 
Scrum In 15 Minutes
Scrum In 15 MinutesScrum In 15 Minutes
Scrum In 15 Minutes
 
3D printer Technology _ A complete presentation
3D printer Technology _ A complete presentation3D printer Technology _ A complete presentation
3D printer Technology _ A complete presentation
 
Google glass ppt
Google glass pptGoogle glass ppt
Google glass ppt
 
Home automation ppt-kamal lamichhane
Home automation ppt-kamal lamichhaneHome automation ppt-kamal lamichhane
Home automation ppt-kamal lamichhane
 
3D Printing
3D Printing3D Printing
3D Printing
 
Overview of Agile Methodology
Overview of Agile MethodologyOverview of Agile Methodology
Overview of Agile Methodology
 
Home automation using android mobiles
Home automation using android mobilesHome automation using android mobiles
Home automation using android mobiles
 
Google glass glasses presentation ppt
Google glass glasses presentation pptGoogle glass glasses presentation ppt
Google glass glasses presentation ppt
 
2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShare2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShare
 

Similar to JS

JavaScript Misunderstood
JavaScript MisunderstoodJavaScript Misunderstood
JavaScript MisunderstoodBhavya Siddappa
 
JavaScript Proven Practises
JavaScript Proven PractisesJavaScript Proven Practises
JavaScript Proven PractisesRobert MacLean
 
Art of Javascript
Art of JavascriptArt of Javascript
Art of JavascriptTarek Yehia
 
Don't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax TreesDon't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax TreesJamund Ferguson
 
JavaScript Cheatsheets with easy way .pdf
JavaScript Cheatsheets with easy way .pdfJavaScript Cheatsheets with easy way .pdf
JavaScript Cheatsheets with easy way .pdfranjanadeore1
 
JavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft TrainingJavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft TrainingRadoslav Georgiev
 
Learn JS concepts by implementing jQuery
Learn JS concepts by implementing jQueryLearn JS concepts by implementing jQuery
Learn JS concepts by implementing jQueryWingify Engineering
 
Javascript Everywhere
Javascript EverywhereJavascript Everywhere
Javascript EverywherePascal Rettig
 
Awesomeness of JavaScript…almost
Awesomeness of JavaScript…almostAwesomeness of JavaScript…almost
Awesomeness of JavaScript…almostQuinton Sheppard
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing UpDavid Padbury
 
A tour on ruby and friends
A tour on ruby and friendsA tour on ruby and friends
A tour on ruby and friends旻琦 潘
 
Web technologies-course 12.pptx
Web technologies-course 12.pptxWeb technologies-course 12.pptx
Web technologies-course 12.pptxStefan Oprea
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)Pavlo Baron
 
Javascript internals
Javascript internalsJavascript internals
Javascript internalsNir Noy
 

Similar to JS (20)

JavaScript Misunderstood
JavaScript MisunderstoodJavaScript Misunderstood
JavaScript Misunderstood
 
JavaScript Proven Practises
JavaScript Proven PractisesJavaScript Proven Practises
JavaScript Proven Practises
 
Art of Javascript
Art of JavascriptArt of Javascript
Art of Javascript
 
jsbasics-slide
jsbasics-slidejsbasics-slide
jsbasics-slide
 
Don't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax TreesDon't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax Trees
 
JavaScript for real men
JavaScript for real menJavaScript for real men
JavaScript for real men
 
Oojs 1.1
Oojs 1.1Oojs 1.1
Oojs 1.1
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 
"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues
 
JavaScript
JavaScriptJavaScript
JavaScript
 
JavaScript Cheatsheets with easy way .pdf
JavaScript Cheatsheets with easy way .pdfJavaScript Cheatsheets with easy way .pdf
JavaScript Cheatsheets with easy way .pdf
 
JavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft TrainingJavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft Training
 
Learn JS concepts by implementing jQuery
Learn JS concepts by implementing jQueryLearn JS concepts by implementing jQuery
Learn JS concepts by implementing jQuery
 
Javascript Everywhere
Javascript EverywhereJavascript Everywhere
Javascript Everywhere
 
Awesomeness of JavaScript…almost
Awesomeness of JavaScript…almostAwesomeness of JavaScript…almost
Awesomeness of JavaScript…almost
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
A tour on ruby and friends
A tour on ruby and friendsA tour on ruby and friends
A tour on ruby and friends
 
Web technologies-course 12.pptx
Web technologies-course 12.pptxWeb technologies-course 12.pptx
Web technologies-course 12.pptx
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
 
Javascript internals
Javascript internalsJavascript internals
Javascript internals
 

Recently uploaded

Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With RoomVIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Roomdivyansh0kumar0
 
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on DeliveryCall Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Deliverybabeytanya
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...SofiyaSharma5
 
VIP Kolkata Call Girl Salt Lake 👉 8250192130 Available With Room
VIP Kolkata Call Girl Salt Lake 👉 8250192130  Available With RoomVIP Kolkata Call Girl Salt Lake 👉 8250192130  Available With Room
VIP Kolkata Call Girl Salt Lake 👉 8250192130 Available With Roomishabajaj13
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Delhi Call girls
 
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Sheetaleventcompany
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebJames Anderson
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...APNIC
 
VIP Call Girls Pune Madhuri 8617697112 Independent Escort Service Pune
VIP Call Girls Pune Madhuri 8617697112 Independent Escort Service PuneVIP Call Girls Pune Madhuri 8617697112 Independent Escort Service Pune
VIP Call Girls Pune Madhuri 8617697112 Independent Escort Service PuneCall girls in Ahmedabad High profile
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGAPNIC
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012rehmti665
 
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With RoomVIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Roomgirls4nights
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)Damian Radcliffe
 
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls KolkataLow Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝soniya singh
 

Recently uploaded (20)

Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
 
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
 
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With RoomVIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
 
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on DeliveryCall Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Delivery
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
 
VIP Kolkata Call Girl Salt Lake 👉 8250192130 Available With Room
VIP Kolkata Call Girl Salt Lake 👉 8250192130  Available With RoomVIP Kolkata Call Girl Salt Lake 👉 8250192130  Available With Room
VIP Kolkata Call Girl Salt Lake 👉 8250192130 Available With Room
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
 
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
 
VIP Call Girls Pune Madhuri 8617697112 Independent Escort Service Pune
VIP Call Girls Pune Madhuri 8617697112 Independent Escort Service PuneVIP Call Girls Pune Madhuri 8617697112 Independent Escort Service Pune
VIP Call Girls Pune Madhuri 8617697112 Independent Escort Service Pune
 
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOG
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
 
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With RoomVIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)
 
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls KolkataLow Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
 

JS

  • 2. What we won’t cover 1. Basics 2. Creating and using variables 3. Funcitons 4. Conditional statements 5. Loops 6. ……...
  • 3. What we will cover 1. Scope 2. SAF (self-invoking anonymous functions) 3. Closures 4. Classes and objects
  • 4. Scope Scope is an area of variable visibility. Most global scope is window object. You can use defined variable in lower scopes, but you can’t use it in upper scope.
  • 5. Scope 1. var word = "Scandiweb", 2. output = function() { 3. console.log(word); 4. }; 5. 6. output(); This is an example of upper scope variable inheritance. This will output to console “Scandiweb” string, as expected.
  • 6. Scope 1. var word = "Scandiweb", 2. output = function() { 3. var word = "Scandi"; 4. console.log(word); 5. }; 6. 7. output(); Lower scope variables will always take precedence over upper ones. So, in this case “Scandi” will be outputted to the console.
  • 7. Scope Why this is important?
  • 8. SAF SAF has no difference from other functions, except it launches itself. (function(){ // code goes here })(); // Other way to write it function() { // code goes here }.call();
  • 9. SAF It is possible to pass any amount of arguments to this functions, as for usual function. 1. (function($, doc, win, undef){ 2. // jQuery is now available with $ 3. })(jQuery, document, window);
  • 10. SAF Why SAF should be used?
  • 11. Closures 1. var sayHello = (function() { 2. var firstWord = 'Hello, '; 3. return function(name) { 4. return firstWord + name + '!'; 5. } 6. })(); 7. 8. alert(sayHello('Scandiweb')); // Hello, Scandiweb! 9. alert(sayHello('Antons')); // Hello, Antons! Why this works this way?
  • 12. Closures 1. var linksArray = document.getElementsByTagName('a'); 2. 3. for (var i = 0; i < 3; i++) { 4. linksArray[i].onclick = function() { 5. console.log(i); 6. } 7. } Considering, we have three links (<a> tags) on page, and on click we want to get link index, what is wrong with this piece of code?
  • 13. Closures Right way to do it: 1. var linksArray = document.getElementsByTagName('a'); 2. 3. for (var i = 0; i < 3; i++) { 4. linksArray[i].onclick = (function(count) { 5. return function() { 6. alert(count); 7. } 8. })(i); 9. }
  • 15. Objects So, we all know what is an object, right? 1. var object = { 2. 'foo': 'bar', 3. 'baz': [ 4. 'foo', 5. 'bar' 6. ] 7. }; Here is a simple object, containing two elements.
  • 16. Classes To make things a bit simplier, let say this: any class in JS basically is a function. At least, up until now - seems like real OOP is coming up in ECMAScript 6. So, lets try to write our own “Class.create()”!
  • 17. Objects 1. var foo = Class.create({ 2. initialize: function() { 3. // code here 4. }, 5. someOtherFunction: function() { 6. // code here 7. } 8. }); 9. 10. // Or, we even can do this 11. var bar = Class.create({}); 12. bar.prototype.initalize = function() { 13. // code here 14. }
  • 18. Classes 1. // Our class creator 2. var Class = { 3. create: function(methods) { 4. function instance() { 5. // Call our contructor function 6. this.start.apply(this, arguments); 7. }; 8. for (key in methods) { // Extend our instance with passed methods 9. if (methods.hasOwnProperty(key)) { 10. instance.prototype[key] = methods[key]; 11. } 12. } 13. return instance; 14. } 15. };
  • 19. Classes 1. var speakerClass = Class.create({ 2. start: function(name) { 3. this.name = name; 4. }, 5. sayHiToSpeaker: function() { 6. return 'Hello, ' + this.name + '!'; 7. } 8. }); 9. var speakerObject1 = new speakerClass('John'), 10. speakerObject2 = new speakerClass('Joe'); 11. speakerClass.prototype.smile = function() { 12. return this.name + ' smiles :)'; 13. };
  • 20. Classes 1. console.log(speakerObject1.sayHiToSpeaker()); // Hello, John! 2. console.log(speakerObject2.sayHiToSpeaker()); // Hello, Joe! 3. 4. console.log(speakerObject1.smile()); // John smiles :) 5. console.log(speakerObject2.smile()); // Joe smiles :)