function Sandbox(){
// 必要なモジュールの初期化
for (var i = 0,len = modules.length; i < len; i++) {
Sandbox.modules[modules[i]](this);
}
}
ここでのthisはSandboxのインスタンスなので、
Sandbox("event", function (box){
});
なら、
Sandbox.modules["event"](this);
という呼び出しがされて、
// box === Sandboxのインスタンス
Sandbox.modules.event = function(box){
box.attachEvent = function(){
}
box.dettachEvent = function(){
}
};
は、要thisにattachEvent等の拡張をしてる。
最後のcallback(this);の時点でのthisは、
Sandbox.modules.event
とかで attachEvent
や dettachEvent
がついてたり、
Sandbox.prototypeでプロトタイプ拡張したメソッドやプロパティがついてるので、
コールバックに渡すboxは拡張してくっつけたメソッドやプロパティが呼べるという感じになる。
function (box){
// Sandbox.modulesで拡張したもの
box.attachEvent(...);
box.dettachEvent(...);
// Sandbox.prototypeで拡張したもの
box.name;
}