Created
February 7, 2012 11:25
-
-
Save larscwallin/1759223 to your computer and use it in GitHub Desktop.
simplx.js
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
simplx = { | |
_debugMode:false, | |
_namespaceSeparator:'.', | |
_extend:function(ns,component){ | |
var nsArray; | |
var targetLocation = this; // First point at the base namespace/Object | |
var currentNs = ''; | |
if(ns !== '' && component instanceof Object){ | |
if(ns.indexOf(this._namespaceSeparator)>0){ | |
if(this._debugMode){console.log('Got namespaces');} | |
nsArray = ns.split(this._namespaceSeparator); | |
for(part in nsArray){ | |
currentNs = nsArray[part]; | |
if(this._debugMode){console.log('Current namespace = '+currentNs);} | |
// Does this namespace exists in the current context? | |
if(targetLocation.hasOwnProperty(currentNs)){ | |
if(this._debugMode){console.log(currentNs+' is an existing namespace.');} | |
// As the namespace exists we re-point the targetLocation. | |
targetLocation = targetLocation[currentNs]; | |
}else{ | |
if(part < nsArray.length-1){ | |
console.log(currentNs+' is not an existing namespace.'); | |
return false; | |
}else{ | |
console.log(currentNs+' is added.'); | |
targetLocation[currentNs] = component; | |
return targetLocation[currentNs]; | |
} | |
} | |
} | |
}else{ | |
// Just one single namespace which means its going in the root of the simplx object | |
return this[ns] = component; | |
} | |
} | |
} | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment