Created
August 31, 2015 13:38
-
-
Save guyjacks/57433a6bc7ffa334f05f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* common.factories.js */ | |
/* | |
* inspired by | |
* | |
* http://www.bennadel.com/blog/2720-creating-and-extending-a-lodash-underscore-service-in-angularjs.htm | |
*/ | |
/* | |
* NOTE: I'm using the immediately-invoked function expression (IIFE pronounced iffy) design pattern. | |
* | |
* The outer parenthesis are a JS syntax short for function(). Its wrapping my function in another an | |
* anonymous function to protect the global scope. | |
* | |
* This prevents var module for overwriting another variable named module on the global scope. | |
* I could have just replaced var module with var name where name is unique to the entire application. | |
* This would however violates encapsulation because it requires knowledge of scope outside the function. | |
* | |
* Although 99% of tuts and examples on the web don't use IIFE, its a recommended practice. Most tuts are simple enough that var collisions are unlikely so they are coded as succinctly as possible. | |
* */ | |
(function() { | |
// by wrapping this factory in a function | |
var module = angular.module('common.factories', []); | |
module.service('_', function($window) { | |
var _ = $window._; | |
delete($window._); | |
/* | |
* | |
* Custom Lodash methods follow. | |
* | |
*/ | |
return (_); | |
}); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment