Created
January 6, 2015 12:18
-
-
Save csdear/22d65d245819680902cc to your computer and use it in GitHub Desktop.
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment