IIFEs vs Namespaced Objects
Video
JavaScript Notes
JavaScript
// Comparing IIFEs and Namespaces as wrappers for your code
//
let objNS = {
name: 'Object Namespace',
init: function( ){
//start rolling the ball
},
action: function( ){
//do some task
}
};
objNS.init( );
let objIIFE = (function( ) {
let myPrivateVar = 'hidden value';
let myPrivateFunc = function( ) {
};
return {
name: 'Object IIFE',
init: function( ){
//start rolling the ball
},
action: function( ){
//do some task
}
}
} ) ( );
Feedback
Submit and view feedback