Scope And Namespace Questions
I was examining various JavaScript libraries for learning purposes. Basically I want to find the best way to initiliaze a namespace and see how pros load up all the associated file
Solution 1:
JS does not assign "by reference", assignment is copying, but when we assign objects, we copy their addresses, not objects "themselves".
Look
window.MyNameSpace = ["libraryFile1.js", "libraryFile2.js", "libraryFile3.js"]
window.MyNameSpace
point to some object in memory. Let's assume its address is 0x12345
var jsFiles = window.MyNameSpace;
jsFiles
now points to the same object (0x12345)
window.MyNameSpace = {...}
window.MyNameSpace
now points to some other object (let it be 0x56789), but jsFiles
still points to the first object (0x12345).
Post a Comment for "Scope And Namespace Questions"