stuart-d2
1/6/2015 - 12:18 PM

Creating a Namespace Using an IFEE □ (Immediate Function Execution Expression -- run immediately, run once etc. ) □ Adds robustne

Creating a Namespace Using an IFEE □ (Immediate Function Execution Expression -- run immediately, run once etc. )
□ Adds robustness to the ns with this IFEE language feature.
□ Use IFEEs to initialize a namespace once with its relevent functionatily. Wrap the code in an IFEE

				 var ns;
				(function (ns) { 
				        ns.Car = function (type) {
				                this.speed = 0; 
				                this.type = type || "No Type"; 
				                }
				                ns.Car.prototype = {
				                        drive: function(newSpeed) { 
				                                this.speed = newSpeed;  
				                                }
				                        }
				                }(ns = ns ||{})); 
				        
				        var bmw = new ns.Car("BMW");
				        console.log(bmw.speed); // outputs 0
				        console.log(bmw.type); // outputs "BMW"
				        bmw.drive(80);
				        console.log(bmw.speed); // outputs 80