Skip to content

Instantly share code, notes, and snippets.

@AhmedTheGeek
Created September 16, 2015 20:42
Show Gist options
  • Save AhmedTheGeek/c237a92219040bd50376 to your computer and use it in GitHub Desktop.
Save AhmedTheGeek/c237a92219040bd50376 to your computer and use it in GitHub Desktop.
/*
* objects-transponder
*
* 2015-09-16
*
* By Ahmed Hussein, http://ahmedgeek.com
* Public Domain.
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
*/
/*
* Description
*
* The point of the object transponder is to have a universal place for your shared objects
* You can register all your objects within the Transponder, then request them anytime from any other object
* It's useful when you're using something like RequireJS and you want to have some shared objects across -
* - all of your definitions
*/
/*
* Usage
*
* Include this file in <head> area, to make it widely accessible
*/
var objectsTransponder = {};
objectsTransponder.registeredObjects = {};
/*
* Registers the Object if it wasn't registered before
*/
objectsTransponder.registerNewObject = function (objectName, Object) {
if (!this.registeredObjects.hasOwnProperty(objectName)) {
this.registeredObjects[objectName] = Object;
}
}
/*
* Returns the requested object
*/
objectsTransponder.requestObject = function (objectName) {
if (this.registeredObjects.hasOwnProperty(objectName)) {
return this.registeredObjects[objectName];
} else if(window.hasOwnProperty(objectName)){
return window[objectName];
} else {
return null;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment