Created
June 15, 2012 19:30
-
-
Save alab1001101/2938325 to your computer and use it in GitHub Desktop.
global props diff
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
(function(global) { | |
var getGlobalProps = function() { | |
var prop, globalProps = {}; | |
for (prop in global) { | |
globalProps[prop] = true; | |
} | |
return globalProps; | |
}, | |
getGlobalPropsDiff = function(globalProps) { | |
var prop, propsDiff = {}; | |
for (prop in global) { | |
if (true !== globalProps[prop]) { | |
propsDiff[prop] = true; | |
} | |
} | |
return propsDiff; | |
}, | |
remapGlobalProps = function(src, propsBeforeLoad) { | |
var propsDiff = getGlobalPropsDiff(propsBeforeLoad), | |
prop; | |
if (!global.container[src]) { | |
global.container[src] = {}; | |
for (prop in propsDiff) { | |
global.container[src][prop] = global[prop]; | |
delete global[prop]; | |
} | |
} | |
}, | |
loadScript = function(src, onLoad) { | |
var propsBeforeLoad = getGlobalProps(), | |
script = document.createElement('script'); | |
script.type = "text/javascript"; | |
script.src = src; | |
script.onload = function() { | |
remapGlobalProps(src, propsBeforeLoad); | |
onLoad(global.container[src]); | |
} | |
document.head.appendChild(script); | |
}, | |
logVersion = function(container) { | |
if (container.jQuery) { | |
console.log(container.$.fn.jquery); | |
} | |
}; | |
global.container = {}; | |
loadScript("http://code.jquery.com/jquery-1.7.2.min.js", logVersion); | |
loadScript("http://code.jquery.com/jquery-1.6.4.min.js", logVersion); | |
})(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment