SlideShare una empresa de Scribd logo
1 de 24
Coding For Kombol
10h January, 2015
Presenter: Riyadh Al Nur
Software Engineer
NewsCred
GitHub: riyadhalnur
Twitter: @riyadhalnur
Blog: blog.verticalaxisbd.com
Coding for Kombol | Riyadh Al Nur
Objects and Functions
Objects
Coding for Kombol | Riyadh Al Nur | Objects and Functions
● Standalone entity with a name and
property
● Object and property names are both
case-sensitive
● Everything’s an object except for null
and undefined
var myObj = {};
var myObj = new Object();
myObj.property1
myObj.Property1 // not the same as above
Object Properties
Coding for Kombol | Riyadh Al Nur | Objects and Functions
● Object properties can be of any type -
strings, functions, arrays
● Properties can be accessed by both dot
and bracket notation
var myObj.prop1 = ‘Hello’;
var myObj[‘prop1’] = ‘Hello’;
Instantiation
Coding for Kombol | Riyadh Al Nur | Objects and Functions
● Object initialisers
● Using constructor functions
● Object.create() method
var myObj = {};
function foo() {};
var bar = new foo();
var foo = {};
var bar = Object.create(foo);
Inheritance
Coding for Kombol | Riyadh Al Nur | Objects and Functions
● JavaScript is a prototype-based language
● All objects inherit from some other
object
● All properties available in prototype
object of constructor
var foo = {};
foo.prototype.prop1 = function() {
return ‘Hello World!’;
};
var bar = new foo();
bar.prop1();
// Hello World!
Methods vs. Prototypes
Coding for Kombol | Riyadh Al Nur | Objects and Functions
● Prototype based instances creates single
instance of properties
● Methods create instance for every single
invocation
● Properties attached via prototype are
shared
● The opposite for method based
properties
Functions
Coding for Kombol | Riyadh Al Nur | Objects and Functions
● First class members in JS
● To be exact, they are first-class objects
● Not the same as procedures
function add(a, b) {
return a + b;
}
// add(2,3) -> 5
Function Scope
Coding for Kombol | Riyadh Al Nur | Objects and Functions
● Functions can access variables inside the
scope it’s defined in only
● Functions inside another function can
access parent variables
var a = 2, b = 3;
function add() {
return a + b; // can access a & b
}
// add() -> 5
Recursion
Coding for Kombol | Riyadh Al Nur | Objects and Functions
● Functions can refer and call themselves
● 3 ways to do so:
● function name
● arguments.callee()
● in-scope variable that refers to
function
var foo = function bar() {};
// 1. bar()
// 2. arguments.callee()
// 3. foo()
Closures
Coding for Kombol | Riyadh Al Nur | Objects and Functions
● Inner function has access to outer
function’s variables
● Outer function does not have access to
inner function’s variables
var foo = (function bar() {
var string = ‘Hello’;
function strings() {
return string + ‘ World!’;
}
return strings();
})();
foo(); // Hello World!
Closures
Coding for Kombol | Riyadh Al Nur | Objects and Functions
● But, what happens when we do
something like this?
var myName = function (name) {
return {
setMyName: function(name) {
name = name;
}
};
};
Closures
Coding for Kombol | Riyadh Al Nur | Objects and Functions
● this refers to where a function is called,
not where it was defined!
NodeJS
The fact
Coding for Kombol | Riyadh Al Nur | Objects and Functions
● NodeJS is a JavaScript runtime
environment - not a language!
So why is it so special?
Coding for Kombol | Riyadh Al Nur | Objects and Functions
● Event driven
● Non-blocking I/O API
● Real-time apps someone?
Not so special but crucial points
● Runs on Google’s V8 JS engine
● Now front-end and back-end are in the
same language!
Under the hood
Coding for Kombol | Riyadh Al Nur | Objects and Functions
● Runs on a single-thread
o uses non-blocking I/O calls
o can handle thousands of concurrent
connections
● Unified API
o use the same services and models on
both server and client side
Under the hood
Coding for Kombol | Riyadh Al Nur | Objects and Functions
Image credit Toptal Engineering blog
Under the hood
Coding for Kombol | Riyadh Al Nur | Objects and Functions
● Event loop
o uses event loops instead of
processes and threads
o no explicit calls required - callbacks,
callbacks, callbacks!
The dark side
Coding for Kombol | Riyadh Al Nur | Objects and Functions
● Single thread = not good for heavy
computation
● App depends on a relational DB
Creating a simple HTTP server
Coding for Kombol | Riyadh Al Nur | Objects and Functions
var http = require(‘http’);
http.createServer(function (req, res) {
res.writeHead(200,
{‘Content-Type’: ‘text/plain’});
res.end(‘Hello World!n’);
}).listen(80);
ExpressJS
Coding for Kombol | Riyadh Al Nur | Objects and Functions
var express = require(‘express’);
// that easy
● A NodeJS web application framework
● Makes the previous example simpler but
more robust and powerful
Questions?

Más contenido relacionado

La actualidad más candente

AOT-compilation of JavaScript with V8
AOT-compilation of JavaScript with V8AOT-compilation of JavaScript with V8
AOT-compilation of JavaScript with V8Phil Eaton
 
Running Through Typescript
Running Through TypescriptRunning Through Typescript
Running Through TypescriptNikhil Wanpal
 
freeCodeCamp Tokyo Meetup #18
freeCodeCamp Tokyo Meetup #18freeCodeCamp Tokyo Meetup #18
freeCodeCamp Tokyo Meetup #18健太 田上
 
Swift language - A fast overview of some features
Swift language - A fast overview of some featuresSwift language - A fast overview of some features
Swift language - A fast overview of some featuresWeverton Timoteo
 
Kotlin & arrow: the functional way
Kotlin & arrow:  the functional wayKotlin & arrow:  the functional way
Kotlin & arrow: the functional waynluaces
 
Demistifying the 3D Web - part 2
Demistifying the 3D Web - part 2Demistifying the 3D Web - part 2
Demistifying the 3D Web - part 2Pietro Grandi
 
Introduction to Higher Order Functions in Scala
Introduction to Higher Order Functions in Scala	Introduction to Higher Order Functions in Scala
Introduction to Higher Order Functions in Scala Knoldus Inc.
 
java8-patterns
java8-patternsjava8-patterns
java8-patternsJustin Lin
 
Introduction to kotlin for Java Developer
Introduction to kotlin for Java DeveloperIntroduction to kotlin for Java Developer
Introduction to kotlin for Java Developertroubledkumi
 
Javascript omg!
Javascript omg!Javascript omg!
Javascript omg!bwullems
 
New c sharp4_features_part_v
New c sharp4_features_part_vNew c sharp4_features_part_v
New c sharp4_features_part_vNico Ludwig
 
Kotlin & Arrow the functional way
Kotlin & Arrow the functional wayKotlin & Arrow the functional way
Kotlin & Arrow the functional wayThoughtworks
 
Google Dart Pecha Kucha from OOP 2012
Google Dart Pecha Kucha from OOP 2012Google Dart Pecha Kucha from OOP 2012
Google Dart Pecha Kucha from OOP 2012Eberhard Wolff
 
CPP13 - Object Orientation
CPP13 - Object OrientationCPP13 - Object Orientation
CPP13 - Object OrientationMichael Heron
 

La actualidad más candente (20)

AOT-compilation of JavaScript with V8
AOT-compilation of JavaScript with V8AOT-compilation of JavaScript with V8
AOT-compilation of JavaScript with V8
 
Running Through Typescript
Running Through TypescriptRunning Through Typescript
Running Through Typescript
 
freeCodeCamp Tokyo Meetup #18
freeCodeCamp Tokyo Meetup #18freeCodeCamp Tokyo Meetup #18
freeCodeCamp Tokyo Meetup #18
 
Swift language - A fast overview of some features
Swift language - A fast overview of some featuresSwift language - A fast overview of some features
Swift language - A fast overview of some features
 
15 Minutes Null
15 Minutes Null15 Minutes Null
15 Minutes Null
 
Kotlin & arrow: the functional way
Kotlin & arrow:  the functional wayKotlin & arrow:  the functional way
Kotlin & arrow: the functional way
 
Valgrind
ValgrindValgrind
Valgrind
 
Hanoi JUG: Java 8 & lambdas
Hanoi JUG: Java 8 & lambdasHanoi JUG: Java 8 & lambdas
Hanoi JUG: Java 8 & lambdas
 
C#
C#C#
C#
 
C#
C#C#
C#
 
C#
C#C#
C#
 
Demistifying the 3D Web - part 2
Demistifying the 3D Web - part 2Demistifying the 3D Web - part 2
Demistifying the 3D Web - part 2
 
Introduction to Higher Order Functions in Scala
Introduction to Higher Order Functions in Scala	Introduction to Higher Order Functions in Scala
Introduction to Higher Order Functions in Scala
 
java8-patterns
java8-patternsjava8-patterns
java8-patterns
 
Introduction to kotlin for Java Developer
Introduction to kotlin for Java DeveloperIntroduction to kotlin for Java Developer
Introduction to kotlin for Java Developer
 
Javascript omg!
Javascript omg!Javascript omg!
Javascript omg!
 
New c sharp4_features_part_v
New c sharp4_features_part_vNew c sharp4_features_part_v
New c sharp4_features_part_v
 
Kotlin & Arrow the functional way
Kotlin & Arrow the functional wayKotlin & Arrow the functional way
Kotlin & Arrow the functional way
 
Google Dart Pecha Kucha from OOP 2012
Google Dart Pecha Kucha from OOP 2012Google Dart Pecha Kucha from OOP 2012
Google Dart Pecha Kucha from OOP 2012
 
CPP13 - Object Orientation
CPP13 - Object OrientationCPP13 - Object Orientation
CPP13 - Object Orientation
 

Destacado

Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side JavascriptJulie Iskander
 
01659-ANSF-translation
01659-ANSF-translation01659-ANSF-translation
01659-ANSF-translationNicola Marchi
 
Pharmaceutical R&D China Sourcing Pilot Final Report
Pharmaceutical R&D  China Sourcing Pilot  Final Report Pharmaceutical R&D  China Sourcing Pilot  Final Report
Pharmaceutical R&D China Sourcing Pilot Final Report Dragon Sourcing
 
Ransomware is Here: Fundamentals Everyone Needs to Know
Ransomware is Here: Fundamentals Everyone Needs to KnowRansomware is Here: Fundamentals Everyone Needs to Know
Ransomware is Here: Fundamentals Everyone Needs to KnowJeremiah Grossman
 
Tce pe - 2013 - prestação de contas compesa exercício 2008 - necessidade c...
Tce pe - 2013 - prestação de contas compesa exercício 2008 - necessidade c...Tce pe - 2013 - prestação de contas compesa exercício 2008 - necessidade c...
Tce pe - 2013 - prestação de contas compesa exercício 2008 - necessidade c...Noelia Brito
 
Journal of Industrial Safety Engineering vol 3 issue 3
Journal of Industrial Safety Engineering vol 3 issue 3Journal of Industrial Safety Engineering vol 3 issue 3
Journal of Industrial Safety Engineering vol 3 issue 3STM Journals
 
Packaging and chemicals case study
Packaging and chemicals case studyPackaging and chemicals case study
Packaging and chemicals case studyDragon Sourcing
 
World Peace Yoga School : Ayurveda
World Peace Yoga School : AyurvedaWorld Peace Yoga School : Ayurveda
World Peace Yoga School : AyurvedaYoga School
 
Research & Reviews A Journal of Immunology vol 6 issue 3
Research & Reviews A Journal of Immunology vol 6 issue 3Research & Reviews A Journal of Immunology vol 6 issue 3
Research & Reviews A Journal of Immunology vol 6 issue 3STM Journals
 

Destacado (13)

Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side Javascript
 
Presentación1
Presentación1Presentación1
Presentación1
 
01659-ANSF-translation
01659-ANSF-translation01659-ANSF-translation
01659-ANSF-translation
 
Pharmaceutical R&D China Sourcing Pilot Final Report
Pharmaceutical R&D  China Sourcing Pilot  Final Report Pharmaceutical R&D  China Sourcing Pilot  Final Report
Pharmaceutical R&D China Sourcing Pilot Final Report
 
Ransomware is Here: Fundamentals Everyone Needs to Know
Ransomware is Here: Fundamentals Everyone Needs to KnowRansomware is Here: Fundamentals Everyone Needs to Know
Ransomware is Here: Fundamentals Everyone Needs to Know
 
Tce pe - 2013 - prestação de contas compesa exercício 2008 - necessidade c...
Tce pe - 2013 - prestação de contas compesa exercício 2008 - necessidade c...Tce pe - 2013 - prestação de contas compesa exercício 2008 - necessidade c...
Tce pe - 2013 - prestação de contas compesa exercício 2008 - necessidade c...
 
Journal of Industrial Safety Engineering vol 3 issue 3
Journal of Industrial Safety Engineering vol 3 issue 3Journal of Industrial Safety Engineering vol 3 issue 3
Journal of Industrial Safety Engineering vol 3 issue 3
 
Sp chap2
Sp chap2Sp chap2
Sp chap2
 
FossilShale Corporate Overview
FossilShale Corporate OverviewFossilShale Corporate Overview
FossilShale Corporate Overview
 
Packaging and chemicals case study
Packaging and chemicals case studyPackaging and chemicals case study
Packaging and chemicals case study
 
World Peace Yoga School : Ayurveda
World Peace Yoga School : AyurvedaWorld Peace Yoga School : Ayurveda
World Peace Yoga School : Ayurveda
 
Bachilleratodigital wix
Bachilleratodigital wixBachilleratodigital wix
Bachilleratodigital wix
 
Research & Reviews A Journal of Immunology vol 6 issue 3
Research & Reviews A Journal of Immunology vol 6 issue 3Research & Reviews A Journal of Immunology vol 6 issue 3
Research & Reviews A Journal of Immunology vol 6 issue 3
 

Similar a Code for kombol - Objects and Functions in JS and NodeJS

Ch-4 Middleware Architectures.pptx
Ch-4 Middleware Architectures.pptxCh-4 Middleware Architectures.pptx
Ch-4 Middleware Architectures.pptxdagilema
 
Lecture4 corba
Lecture4   corbaLecture4   corba
Lecture4 corbapoovi117
 
Dmytro Dziubenko "Developer's toolchain"
Dmytro Dziubenko "Developer's toolchain"Dmytro Dziubenko "Developer's toolchain"
Dmytro Dziubenko "Developer's toolchain"Fwdays
 
Writing mruby Debugger
Writing mruby DebuggerWriting mruby Debugger
Writing mruby Debuggeryamanekko
 
Jit builder status and directions 2018 03-28
Jit builder status and directions 2018 03-28Jit builder status and directions 2018 03-28
Jit builder status and directions 2018 03-28Mark Stoodley
 
Erp5 presentation plone_symosium_tokyo_2015
Erp5 presentation plone_symosium_tokyo_2015Erp5 presentation plone_symosium_tokyo_2015
Erp5 presentation plone_symosium_tokyo_2015taharayusei
 
Best Angular JS training in Hyderabad, India
Best Angular JS training in Hyderabad, IndiaBest Angular JS training in Hyderabad, India
Best Angular JS training in Hyderabad, IndiaN Benchmark IT Solutions
 
Kotlin in the age of digital transformation
Kotlin   in the age of digital transformationKotlin   in the age of digital transformation
Kotlin in the age of digital transformationRajmahendra Hegde
 
JavaScript: Patterns, Part 3
JavaScript: Patterns, Part  3JavaScript: Patterns, Part  3
JavaScript: Patterns, Part 3Chris Farrell
 
Building modular enterprise scale angular js applications
Building modular enterprise scale angular js applicationsBuilding modular enterprise scale angular js applications
Building modular enterprise scale angular js applicationsJonathan Fontanez
 
Functional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNextFunctional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNextUnfold UI
 
Testing with Express, Mocha & Chai
Testing with Express, Mocha & ChaiTesting with Express, Mocha & Chai
Testing with Express, Mocha & ChaiJoerg Henning
 
Enforcing API Design Rules for High Quality Code Generation
Enforcing API Design Rules for High Quality Code GenerationEnforcing API Design Rules for High Quality Code Generation
Enforcing API Design Rules for High Quality Code GenerationTim Burks
 
JavaScript objects and functions
JavaScript objects and functionsJavaScript objects and functions
JavaScript objects and functionsVictor Verhaagen
 
JavaScript Interview Questions Part - 1.pdf
JavaScript Interview Questions Part - 1.pdfJavaScript Interview Questions Part - 1.pdf
JavaScript Interview Questions Part - 1.pdfkatarichallenge
 
Intro to java 8
Intro to java 8Intro to java 8
Intro to java 8John Godoi
 

Similar a Code for kombol - Objects and Functions in JS and NodeJS (20)

Ch-4 Middleware Architectures.pptx
Ch-4 Middleware Architectures.pptxCh-4 Middleware Architectures.pptx
Ch-4 Middleware Architectures.pptx
 
Lecture4 corba
Lecture4   corbaLecture4   corba
Lecture4 corba
 
Dmytro Dziubenko "Developer's toolchain"
Dmytro Dziubenko "Developer's toolchain"Dmytro Dziubenko "Developer's toolchain"
Dmytro Dziubenko "Developer's toolchain"
 
Writing mruby Debugger
Writing mruby DebuggerWriting mruby Debugger
Writing mruby Debugger
 
Jit builder status and directions 2018 03-28
Jit builder status and directions 2018 03-28Jit builder status and directions 2018 03-28
Jit builder status and directions 2018 03-28
 
Erp5 presentation plone_symosium_tokyo_2015
Erp5 presentation plone_symosium_tokyo_2015Erp5 presentation plone_symosium_tokyo_2015
Erp5 presentation plone_symosium_tokyo_2015
 
Learn TypeScript from scratch
Learn TypeScript from scratchLearn TypeScript from scratch
Learn TypeScript from scratch
 
Best Angular JS training in Hyderabad, India
Best Angular JS training in Hyderabad, IndiaBest Angular JS training in Hyderabad, India
Best Angular JS training in Hyderabad, India
 
Kotlin in the age of digital transformation
Kotlin   in the age of digital transformationKotlin   in the age of digital transformation
Kotlin in the age of digital transformation
 
Web Assembly
Web AssemblyWeb Assembly
Web Assembly
 
JavaScript: Patterns, Part 3
JavaScript: Patterns, Part  3JavaScript: Patterns, Part  3
JavaScript: Patterns, Part 3
 
Building modular enterprise scale angular js applications
Building modular enterprise scale angular js applicationsBuilding modular enterprise scale angular js applications
Building modular enterprise scale angular js applications
 
From Perl To Elixir
From Perl To ElixirFrom Perl To Elixir
From Perl To Elixir
 
Functional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNextFunctional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNext
 
Testing with Express, Mocha & Chai
Testing with Express, Mocha & ChaiTesting with Express, Mocha & Chai
Testing with Express, Mocha & Chai
 
Enforcing API Design Rules for High Quality Code Generation
Enforcing API Design Rules for High Quality Code GenerationEnforcing API Design Rules for High Quality Code Generation
Enforcing API Design Rules for High Quality Code Generation
 
Advance JS and oop
Advance JS and oopAdvance JS and oop
Advance JS and oop
 
JavaScript objects and functions
JavaScript objects and functionsJavaScript objects and functions
JavaScript objects and functions
 
JavaScript Interview Questions Part - 1.pdf
JavaScript Interview Questions Part - 1.pdfJavaScript Interview Questions Part - 1.pdf
JavaScript Interview Questions Part - 1.pdf
 
Intro to java 8
Intro to java 8Intro to java 8
Intro to java 8
 

Último

Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 

Último (20)

Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 

Code for kombol - Objects and Functions in JS and NodeJS

  • 1. Coding For Kombol 10h January, 2015 Presenter: Riyadh Al Nur Software Engineer NewsCred
  • 2. GitHub: riyadhalnur Twitter: @riyadhalnur Blog: blog.verticalaxisbd.com Coding for Kombol | Riyadh Al Nur
  • 4. Objects Coding for Kombol | Riyadh Al Nur | Objects and Functions ● Standalone entity with a name and property ● Object and property names are both case-sensitive ● Everything’s an object except for null and undefined var myObj = {}; var myObj = new Object(); myObj.property1 myObj.Property1 // not the same as above
  • 5. Object Properties Coding for Kombol | Riyadh Al Nur | Objects and Functions ● Object properties can be of any type - strings, functions, arrays ● Properties can be accessed by both dot and bracket notation var myObj.prop1 = ‘Hello’; var myObj[‘prop1’] = ‘Hello’;
  • 6. Instantiation Coding for Kombol | Riyadh Al Nur | Objects and Functions ● Object initialisers ● Using constructor functions ● Object.create() method var myObj = {}; function foo() {}; var bar = new foo(); var foo = {}; var bar = Object.create(foo);
  • 7. Inheritance Coding for Kombol | Riyadh Al Nur | Objects and Functions ● JavaScript is a prototype-based language ● All objects inherit from some other object ● All properties available in prototype object of constructor var foo = {}; foo.prototype.prop1 = function() { return ‘Hello World!’; }; var bar = new foo(); bar.prop1(); // Hello World!
  • 8. Methods vs. Prototypes Coding for Kombol | Riyadh Al Nur | Objects and Functions ● Prototype based instances creates single instance of properties ● Methods create instance for every single invocation ● Properties attached via prototype are shared ● The opposite for method based properties
  • 9. Functions Coding for Kombol | Riyadh Al Nur | Objects and Functions ● First class members in JS ● To be exact, they are first-class objects ● Not the same as procedures function add(a, b) { return a + b; } // add(2,3) -> 5
  • 10. Function Scope Coding for Kombol | Riyadh Al Nur | Objects and Functions ● Functions can access variables inside the scope it’s defined in only ● Functions inside another function can access parent variables var a = 2, b = 3; function add() { return a + b; // can access a & b } // add() -> 5
  • 11. Recursion Coding for Kombol | Riyadh Al Nur | Objects and Functions ● Functions can refer and call themselves ● 3 ways to do so: ● function name ● arguments.callee() ● in-scope variable that refers to function var foo = function bar() {}; // 1. bar() // 2. arguments.callee() // 3. foo()
  • 12. Closures Coding for Kombol | Riyadh Al Nur | Objects and Functions ● Inner function has access to outer function’s variables ● Outer function does not have access to inner function’s variables var foo = (function bar() { var string = ‘Hello’; function strings() { return string + ‘ World!’; } return strings(); })(); foo(); // Hello World!
  • 13. Closures Coding for Kombol | Riyadh Al Nur | Objects and Functions ● But, what happens when we do something like this? var myName = function (name) { return { setMyName: function(name) { name = name; } }; };
  • 14. Closures Coding for Kombol | Riyadh Al Nur | Objects and Functions ● this refers to where a function is called, not where it was defined!
  • 16. The fact Coding for Kombol | Riyadh Al Nur | Objects and Functions ● NodeJS is a JavaScript runtime environment - not a language!
  • 17. So why is it so special? Coding for Kombol | Riyadh Al Nur | Objects and Functions ● Event driven ● Non-blocking I/O API ● Real-time apps someone? Not so special but crucial points ● Runs on Google’s V8 JS engine ● Now front-end and back-end are in the same language!
  • 18. Under the hood Coding for Kombol | Riyadh Al Nur | Objects and Functions ● Runs on a single-thread o uses non-blocking I/O calls o can handle thousands of concurrent connections ● Unified API o use the same services and models on both server and client side
  • 19. Under the hood Coding for Kombol | Riyadh Al Nur | Objects and Functions Image credit Toptal Engineering blog
  • 20. Under the hood Coding for Kombol | Riyadh Al Nur | Objects and Functions ● Event loop o uses event loops instead of processes and threads o no explicit calls required - callbacks, callbacks, callbacks!
  • 21. The dark side Coding for Kombol | Riyadh Al Nur | Objects and Functions ● Single thread = not good for heavy computation ● App depends on a relational DB
  • 22. Creating a simple HTTP server Coding for Kombol | Riyadh Al Nur | Objects and Functions var http = require(‘http’); http.createServer(function (req, res) { res.writeHead(200, {‘Content-Type’: ‘text/plain’}); res.end(‘Hello World!n’); }).listen(80);
  • 23. ExpressJS Coding for Kombol | Riyadh Al Nur | Objects and Functions var express = require(‘express’); // that easy ● A NodeJS web application framework ● Makes the previous example simpler but more robust and powerful