JavaScript - My Misc Notes
This blog is managed in 'JS - my notes.md' file
JavaScript - My Misc Notes
Scope
- Lexical scope: function written within function can access all of the parent's vars and parms.
- Function can be called before it is defined - before in the text.
- You can define a regular function anywhere in the code.
- Pronoun this is calculated when the code is executed. If we call a method that uses this outside of the object it belongs to, this will be undefined.
Modules
- IIFE way
- More common:
define( [array], object);
It comes from CommonJS and RequireJS more or less (see this). If object is a function, its parms are 1 to 1 with elements of the array, each of which specifies a dependency module e.g. 'rs/form/abstract/invoice.controller'
. It is guaranted that the function will run only once even if more than one module list this module as their dependency.
No comments:
Post a Comment