Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script src="tom.js"></script>
- <script src="tonny.js"></script>
- <script src="scott.js"></script>
- <script>
- speak();
- /* This will create a naming conflict as
- scott, tonny and tom, all use the same function */
- </script>
- var tom = {};
- (function(namespace) {
- namespace.speak = function() {
- console.log("I am Tom !");
- };
- })(tom );
- var tonny = {};
- (function() {
- this.speak = function() {
- console.log("I am Tonny !")
- };
- }).apply(tonny );
- var scott = {};
- (function() {
- var speakSoftly = function() {
- console.log("I am Scott !")
- };
- this.speak = function() {
- speakSoftly();
- };
- }).call(scott );
- tom.speak();
- tonny.speak();
- scott.speak();
- scott.speakSoftly; // speakSoftly is local to IIFE block
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement