SlideShare a Scribd company logo
JavaScript function
Define a functionfunction f(msg) {alert(msg);}// overridefunction f(msg1, msg2) {alert(msg1 + ' ' + msg2);}// arguments keywordfunction f() {    for (var i = 0; i < arguments.length; i ++ ) {        alert(arguments[i]);}}// callf();
Define a classvarMyAlert = function (msg) {   this.msg = msg;// define a methodthis.f = function () {        alert('Hello ' + this.msg);   };};varmyalert = new MyAlert('Mary');// call f methodmyalert.f();
Define a class by prototypevarMyAlert = function (msg) {   this.msg = msg;};// use prototype to define a methodMyAlert.prototype.f = function () {   alert(this.msg);};prototype definition uses less memory
Built-in typesNumbervarnum = new Number(2); or  varnum= 2; Objectvarobj = new Object(); or  varobj = {}; Arrayvararr = new Array(1, 2, 3); or vararr = [1, 2, 3];Stringvarstr = new String('Hello'); or varstr = 'Hello';Regular expressionvar regex = new RegExp('\s*'); or varregex = /\s*/;etc... - w3schools.com/js
String prototypeString.prototype.f = function () {   alert(this);};varstr = 'Hello Mary';str.f();
Define a function (more)// goes to top of current scopefunction f(msg) {     alert(msg);}// assignmentvarf = function (msg) {    alert(msg);};// use new keywordvar f = new Function('msg', 'alert(msg);');
Function prototypeFunction.prototype.f= function () {   alert(this.toString());};var f = function () {   alert('This is a function.');};// does NOT alert "This is a function." f.f();
Anonymous function(function (msg) {    alert('This is ' + msg);})('anonymous');(function (msg) {// this line does NOT get executed    alert('This is ' + msg);}).f();
Callbackfunction f(callback) {   callback();}function dosomething() {    alert('This is a callback function.');}f(dosomething);
Return a functionfunction f() {varnum= 1;// num can be accessed in inner functionvarinnerf = function () {alert( 'inner function called, num: ' + num);    };   return innerf;}// f2 now is a functionvarf2 = f();f2();
Closurefunction f() {varnum= 1;// num can be accessed in inner functionvarinnerf = function () {num ++;        alert( 'inner function called, num: ' + num );    };    return innerf;}// f2 now is a functionvar f2 = f();f2();
SummaryFuntionis a objectused to create classcan be passed as parametercan be returnedcreates a closure when defined in another function
Ad

Recommended

Javascript function
Javascript function
LearningTech
 
JavaScript Functions
JavaScript Functions
Brian Moschel
 
LinkedIn TBC JavaScript 100: Functions
LinkedIn TBC JavaScript 100: Functions
Adam Crabtree
 
Ff
Ff
bansalamit2010
 
Java script
Java script
Dhananjay Kumar
 
JavaScript Functions
JavaScript Functions
Colin DeCarlo
 
03 function overloading
03 function overloading
Jasleen Kaur (Chandigarh University)
 
Unit 6 pointers
Unit 6 pointers
George Erfesoglou
 
C++ Function
C++ Function
Hajar
 
Hello Swift 3/5 - Function
Hello Swift 3/5 - Function
Cody Yun
 
Function
Function
venkatme83
 
Function overloading(C++)
Function overloading(C++)
Ritika Sharma
 
Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)
Rick Copeland
 
Extend GraphQL with directives
Extend GraphQL with directives
Greg Bergé
 
OOP and FP - Become a Better Programmer
OOP and FP - Become a Better Programmer
Mario Fusco
 
Functions in python
Functions in python
Ilian Iliev
 
Clojure basics
Clojure basics
Knoldus Inc.
 
Functions in C++
Functions in C++
home
 
Function overloading
Function overloading
Sudeshna Biswas
 
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Mario Fusco
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Mario Fusco
 
From object oriented to functional domain modeling
From object oriented to functional domain modeling
Mario Fusco
 
삼성 바다 앱개발 실패 노하우 2부
삼성 바다 앱개발 실패 노하우 2부
mosaicnet
 
OO JS for AS3 Devs
OO JS for AS3 Devs
Jason Hanson
 
Function C++
Function C++
Shahzad Afridi
 
FP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyond
Mario Fusco
 
How to practice functional programming in react
How to practice functional programming in react
Netta Bondy
 
Introduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in Haskell
nebuta
 
Function work in JavaScript
Function work in JavaScript
Rhio Kim
 
Resthub framework presentation
Resthub framework presentation
Sébastien Deleuze
 

More Related Content

What's hot (20)

C++ Function
C++ Function
Hajar
 
Hello Swift 3/5 - Function
Hello Swift 3/5 - Function
Cody Yun
 
Function
Function
venkatme83
 
Function overloading(C++)
Function overloading(C++)
Ritika Sharma
 
Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)
Rick Copeland
 
Extend GraphQL with directives
Extend GraphQL with directives
Greg Bergé
 
OOP and FP - Become a Better Programmer
OOP and FP - Become a Better Programmer
Mario Fusco
 
Functions in python
Functions in python
Ilian Iliev
 
Clojure basics
Clojure basics
Knoldus Inc.
 
Functions in C++
Functions in C++
home
 
Function overloading
Function overloading
Sudeshna Biswas
 
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Mario Fusco
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Mario Fusco
 
From object oriented to functional domain modeling
From object oriented to functional domain modeling
Mario Fusco
 
삼성 바다 앱개발 실패 노하우 2부
삼성 바다 앱개발 실패 노하우 2부
mosaicnet
 
OO JS for AS3 Devs
OO JS for AS3 Devs
Jason Hanson
 
Function C++
Function C++
Shahzad Afridi
 
FP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyond
Mario Fusco
 
How to practice functional programming in react
How to practice functional programming in react
Netta Bondy
 
Introduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in Haskell
nebuta
 
C++ Function
C++ Function
Hajar
 
Hello Swift 3/5 - Function
Hello Swift 3/5 - Function
Cody Yun
 
Function overloading(C++)
Function overloading(C++)
Ritika Sharma
 
Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)
Rick Copeland
 
Extend GraphQL with directives
Extend GraphQL with directives
Greg Bergé
 
OOP and FP - Become a Better Programmer
OOP and FP - Become a Better Programmer
Mario Fusco
 
Functions in python
Functions in python
Ilian Iliev
 
Functions in C++
Functions in C++
home
 
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Mario Fusco
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Mario Fusco
 
From object oriented to functional domain modeling
From object oriented to functional domain modeling
Mario Fusco
 
삼성 바다 앱개발 실패 노하우 2부
삼성 바다 앱개발 실패 노하우 2부
mosaicnet
 
OO JS for AS3 Devs
OO JS for AS3 Devs
Jason Hanson
 
FP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyond
Mario Fusco
 
How to practice functional programming in react
How to practice functional programming in react
Netta Bondy
 
Introduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in Haskell
nebuta
 

Viewers also liked (20)

Function work in JavaScript
Function work in JavaScript
Rhio Kim
 
Resthub framework presentation
Resthub framework presentation
Sébastien Deleuze
 
JavaScript Conditional Statements
JavaScript Conditional Statements
Marlon Jamera
 
Writing MySQL User-defined Functions in JavaScript
Writing MySQL User-defined Functions in JavaScript
Roland Bouman
 
JavaScript Control Statements I
JavaScript Control Statements I
Reem Alattas
 
Loops in JavaScript
Loops in JavaScript
Florence Davis
 
Javascript conditional statements
Javascript conditional statements
nobel mujuji
 
Loops in java script
Loops in java script
Ravi Bhadauria
 
JavaScript Functions
JavaScript Functions
Reem Alattas
 
Functional Javascript
Functional Javascript
guest4d57e6
 
直接照会により公開された芸術監督データ
直接照会により公開された芸術監督データ
長野市議会議員小泉一真
 
Senior Project
Senior Project
batboy1993
 
Power Notes: Measurements and Dealing with Data-2011
Power Notes: Measurements and Dealing with Data-2011
jmori1
 
Photo album latest slideshow1
Photo album latest slideshow1
hussain56
 
Ocnele mari
Ocnele mari
balada65
 
推推共享介绍 副本
推推共享介绍 副本
繁斌 孔
 
Watch reviews
Watch reviews
The Best Watches
 
Themes ways of the world
Themes ways of the world
ashleighalece
 
Module 1
Module 1
Xiyue Yang
 
Function work in JavaScript
Function work in JavaScript
Rhio Kim
 
Resthub framework presentation
Resthub framework presentation
Sébastien Deleuze
 
JavaScript Conditional Statements
JavaScript Conditional Statements
Marlon Jamera
 
Writing MySQL User-defined Functions in JavaScript
Writing MySQL User-defined Functions in JavaScript
Roland Bouman
 
JavaScript Control Statements I
JavaScript Control Statements I
Reem Alattas
 
Javascript conditional statements
Javascript conditional statements
nobel mujuji
 
JavaScript Functions
JavaScript Functions
Reem Alattas
 
Functional Javascript
Functional Javascript
guest4d57e6
 
Senior Project
Senior Project
batboy1993
 
Power Notes: Measurements and Dealing with Data-2011
Power Notes: Measurements and Dealing with Data-2011
jmori1
 
Photo album latest slideshow1
Photo album latest slideshow1
hussain56
 
Ocnele mari
Ocnele mari
balada65
 
推推共享介绍 副本
推推共享介绍 副本
繁斌 孔
 
Themes ways of the world
Themes ways of the world
ashleighalece
 
Ad

Similar to Javascript Function (20)

Four Ways to add Features to Ext JS
Four Ways to add Features to Ext JS
Shea Frederick
 
JavaScript Classes and Inheritance
JavaScript Classes and Inheritance
marcheiligers
 
25-functions.ppt
25-functions.ppt
JyothiAmpally
 
this
this
偉格 高
 
Ian 20150116 java script oop
Ian 20150116 java script oop
LearningTech
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
mussawir20
 
Exercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera Cymbron
cymbron
 
JavaScript and UI Architecture Best Practices
JavaScript and UI Architecture Best Practices
Siarhei Barysiuk
 
jQuery Namespace Pattern
jQuery Namespace Pattern
Diego Fleury
 
Say It With Javascript
Say It With Javascript
Giovanni Scerra ☃
 
Logic Equations Resolver J Script
Logic Equations Resolver J Script
Roman Agaev
 
運用Closure Compiler 打造高品質的JavaScript
運用Closure Compiler 打造高品質的JavaScript
taobao.com
 
Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015
Lin Yo-An
 
C Programming Language Part 7
C Programming Language Part 7
Rumman Ansari
 
Ext oo
Ext oo
o52tiger
 
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)
Tomohiro Kumagai
 
Ecma script6
Ecma script6
동욱 박
 
Functional Programming In Java
Functional Programming In Java
Andrei Solntsev
 
6976.ppt
6976.ppt
MuhammedSheriefHagra
 
The mighty js_function
The mighty js_function
timotheeg
 
Four Ways to add Features to Ext JS
Four Ways to add Features to Ext JS
Shea Frederick
 
JavaScript Classes and Inheritance
JavaScript Classes and Inheritance
marcheiligers
 
Ian 20150116 java script oop
Ian 20150116 java script oop
LearningTech
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
mussawir20
 
Exercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera Cymbron
cymbron
 
JavaScript and UI Architecture Best Practices
JavaScript and UI Architecture Best Practices
Siarhei Barysiuk
 
jQuery Namespace Pattern
jQuery Namespace Pattern
Diego Fleury
 
Logic Equations Resolver J Script
Logic Equations Resolver J Script
Roman Agaev
 
運用Closure Compiler 打造高品質的JavaScript
運用Closure Compiler 打造高品質的JavaScript
taobao.com
 
Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015
Lin Yo-An
 
C Programming Language Part 7
C Programming Language Part 7
Rumman Ansari
 
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)
Tomohiro Kumagai
 
Functional Programming In Java
Functional Programming In Java
Andrei Solntsev
 
The mighty js_function
The mighty js_function
timotheeg
 
Ad

Recently uploaded (20)

Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
Daily Lesson Log MATATAG ICT TEchnology 8
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
Mastering AI Workflows with FME by Mark Döring
Mastering AI Workflows with FME by Mark Döring
Safe Software
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
 
From Manual to Auto Searching- FME in the Driver's Seat
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
Priyanka Aash
 
The Future of Product Management in AI ERA.pdf
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
Fwdays
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Priyanka Aash
 
Cyber Defense Matrix Workshop - RSA Conference
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
 
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
 
“MPU+: A Transformative Solution for Next-Gen AI at the Edge,” a Presentation...
“MPU+: A Transformative Solution for Next-Gen AI at the Edge,” a Presentation...
Edge AI and Vision Alliance
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
Daily Lesson Log MATATAG ICT TEchnology 8
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
Mastering AI Workflows with FME by Mark Döring
Mastering AI Workflows with FME by Mark Döring
Safe Software
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
 
From Manual to Auto Searching- FME in the Driver's Seat
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
Priyanka Aash
 
The Future of Product Management in AI ERA.pdf
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
Fwdays
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Priyanka Aash
 
Cyber Defense Matrix Workshop - RSA Conference
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
 
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
 
“MPU+: A Transformative Solution for Next-Gen AI at the Edge,” a Presentation...
“MPU+: A Transformative Solution for Next-Gen AI at the Edge,” a Presentation...
Edge AI and Vision Alliance
 

Javascript Function

  • 2. Define a functionfunction f(msg) {alert(msg);}// overridefunction f(msg1, msg2) {alert(msg1 + ' ' + msg2);}// arguments keywordfunction f() { for (var i = 0; i < arguments.length; i ++ ) { alert(arguments[i]);}}// callf();
  • 3. Define a classvarMyAlert = function (msg) { this.msg = msg;// define a methodthis.f = function () { alert('Hello ' + this.msg); };};varmyalert = new MyAlert('Mary');// call f methodmyalert.f();
  • 4. Define a class by prototypevarMyAlert = function (msg) { this.msg = msg;};// use prototype to define a methodMyAlert.prototype.f = function () { alert(this.msg);};prototype definition uses less memory
  • 5. Built-in typesNumbervarnum = new Number(2); or varnum= 2; Objectvarobj = new Object(); or varobj = {}; Arrayvararr = new Array(1, 2, 3); or vararr = [1, 2, 3];Stringvarstr = new String('Hello'); or varstr = 'Hello';Regular expressionvar regex = new RegExp('\s*'); or varregex = /\s*/;etc... - w3schools.com/js
  • 6. String prototypeString.prototype.f = function () { alert(this);};varstr = 'Hello Mary';str.f();
  • 7. Define a function (more)// goes to top of current scopefunction f(msg) { alert(msg);}// assignmentvarf = function (msg) { alert(msg);};// use new keywordvar f = new Function('msg', 'alert(msg);');
  • 8. Function prototypeFunction.prototype.f= function () { alert(this.toString());};var f = function () { alert('This is a function.');};// does NOT alert "This is a function." f.f();
  • 9. Anonymous function(function (msg) { alert('This is ' + msg);})('anonymous');(function (msg) {// this line does NOT get executed alert('This is ' + msg);}).f();
  • 10. Callbackfunction f(callback) { callback();}function dosomething() { alert('This is a callback function.');}f(dosomething);
  • 11. Return a functionfunction f() {varnum= 1;// num can be accessed in inner functionvarinnerf = function () {alert( 'inner function called, num: ' + num); }; return innerf;}// f2 now is a functionvarf2 = f();f2();
  • 12. Closurefunction f() {varnum= 1;// num can be accessed in inner functionvarinnerf = function () {num ++; alert( 'inner function called, num: ' + num ); }; return innerf;}// f2 now is a functionvar f2 = f();f2();
  • 13. SummaryFuntionis a objectused to create classcan be passed as parametercan be returnedcreates a closure when defined in another function