3. Show me the code
https://github.com/islomar/poc-javascript/tree/master/alea-technical-friday
4. Sumario
1. Show and hide
2. Hoisting
3. Ola k ase, soi un numero o k ase
4. La globalización de las variables
5. Objetos
6. IIFE
7. Module pattern
8. Herencia y prototipado
9. Invocation patterns
5. Show and hide
Visto por ahí: uso de clase ‘hide’
jQuery ofrece funciones show(), hide() y toggle()
6. Hoisting
● Hoisting = elevar, alzar, levantar
● It is a concept about program load order
● Function expressions vs function declaration/statements.
○ Function expression:
■ var showMeTheMoney = function(){}
■ Never hoisted
■ It loads only when this particular line of code is reached while executing.
○ Function declaration/statements:
■ Builds in memory immediately when the program loads
■ It does not require variable assignment
■ Can be invoked during execution before its actual definition
7. Ola k ase, soi un numero o k ase
Using NaN to check if values are actually JS Numbers seems like
a good idea, but it will try to kill you.
8. La globalización de las variables
Global variable: a variable visible in every scope.
Possible collisions when programs grow...
JS makes it easy to define global variables that can hold all of the assets of your
application.
9. Objetos
● The simple types of JS are numbers, strings, booleans, null and undefined
● All other values are objects: arrays, functions, regular expressions, etc.
● Numbers, strings and booleans have methods but they are immutable.
● Objects are mutable keyed collections.
● Objects are class-free
10. IIFE
IIFE (Immediately Invoked Function Expression) is a JavaScript function that runs as
soon as it is defined.
Used to hide “private” properties: module pattern.
11. Module pattern
The Module pattern is used to further emulate the concept of classes in such a way
that we're able to include both public/private methods and variables inside a single
object, thus shielding particular parts from the global scope.
What this results in is a reduction in the likelihood of our function names conflicting
with other functions defined in additional scripts on the page.
12. Inheritance and protoyping
● JS is a prototypal language, which means that objects inherit directly from other
objects.
● Every object is linked to a prototype object from which it can inherit properties.
● All objects created from object literals are linked to Object.prototype.
● When you make a new object, you can select the object that should be its
prototype.
13. Invocation patterns
● Invoking a function suspends the execution of the current function, passing
control and parameters to the new function.
● In addition to the declared parameters, every function receives two additional
parameters, every function receives two additional parameters: ‘this’ and
arguments.
14. Invocation patterns
● The patterns differ in how the bonus parameter ‘this’ is initialized:
○ Method invocation pattern
○ Function invocation pattern
○ Constructor invocation pattern
○ Apply invocation pattern