kms techcon 2014 - interesting in javascript
DESCRIPTION
My topic in KMS TechCon 2014, an internal technology event at KMS Technology Vietnam companyTRANSCRIPT
![Page 2: KMS TechCon 2014 - Interesting in JavaScript](https://reader035.vdocuments.net/reader035/viewer/2022081519/554f38a7b4c905471e8b4864/html5/thumbnails/2.jpg)
INTERESTING IN JAVASCRIPT
DUY LAMKMS TECHNOLOGY
MAY 2014
![Page 3: KMS TechCon 2014 - Interesting in JavaScript](https://reader035.vdocuments.net/reader035/viewer/2022081519/554f38a7b4c905471e8b4864/html5/thumbnails/3.jpg)
JAVASCRIPT THINGS
function(){ } Closure function(){this.name;} Module Pattern
![Page 4: KMS TechCon 2014 - Interesting in JavaScript](https://reader035.vdocuments.net/reader035/viewer/2022081519/554f38a7b4c905471e8b4864/html5/thumbnails/4.jpg)
FUNCTION
function is a Function object Local variable arguments object (it is not
an Array) function calls itself
Conflicting on variable names
check out the demo @ http://bit.ly/techcon2014-function
![Page 5: KMS TechCon 2014 - Interesting in JavaScript](https://reader035.vdocuments.net/reader035/viewer/2022081519/554f38a7b4c905471e8b4864/html5/thumbnails/5.jpg)
CLOSURE
function can access variables declared in outer scope
check out the demo @ http://bit.ly/techcon2014-closure
![Page 6: KMS TechCon 2014 - Interesting in JavaScript](https://reader035.vdocuments.net/reader035/viewer/2022081519/554f38a7b4c905471e8b4864/html5/thumbnails/6.jpg)
CLOSURE (CONT.)
something wrong here
![Page 7: KMS TechCon 2014 - Interesting in JavaScript](https://reader035.vdocuments.net/reader035/viewer/2022081519/554f38a7b4c905471e8b4864/html5/thumbnails/7.jpg)
CLOSURE (CONT.)
showNameFunc became a closure closure is a Function object closure has environment when the function is created
![Page 8: KMS TechCon 2014 - Interesting in JavaScript](https://reader035.vdocuments.net/reader035/viewer/2022081519/554f38a7b4c905471e8b4864/html5/thumbnails/8.jpg)
THIS KEYWORD
Context of this : in global and in a function Bind a particular object to this inside a
function
check out the demo @ http://bit.ly/techcon2014-this
![Page 9: KMS TechCon 2014 - Interesting in JavaScript](https://reader035.vdocuments.net/reader035/viewer/2022081519/554f38a7b4c905471e8b4864/html5/thumbnails/9.jpg)
MODULE PATTERN – THE PROBLEM
Global variable’s problems Implicit global variable Bad integrationwith other programs
![Page 10: KMS TechCon 2014 - Interesting in JavaScript](https://reader035.vdocuments.net/reader035/viewer/2022081519/554f38a7b4c905471e8b4864/html5/thumbnails/10.jpg)
MODULE PATTERN – SOLUTION
here isan example
![Page 11: KMS TechCon 2014 - Interesting in JavaScript](https://reader035.vdocuments.net/reader035/viewer/2022081519/554f38a7b4c905471e8b4864/html5/thumbnails/11.jpg)
MODULE PATTERN – ADVANCE USES
global import
module exportaugment module
![Page 12: KMS TechCon 2014 - Interesting in JavaScript](https://reader035.vdocuments.net/reader035/viewer/2022081519/554f38a7b4c905471e8b4864/html5/thumbnails/12.jpg)
REFERENCE
• https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope
• https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this
• http://www.adequatelygood.com/JavaScript-Module-Pattern-In-Depth.html
• https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Closures• Demo:
– http://bit.ly/techcon2014-function– http://bit.ly/techcon2014-this– http://bit.ly/techcon2014-closure