【发布时间】:2010-05-31 00:48:39
【问题描述】:
好的,我看到了一些针对 Java 的参考,但不是 javascript(希望您知道它们完全不同)。所以这里是特定的代码:
function Sandbox() {
var args = Array.prototype.slice.call(arguments)
, callback = args.pop()
, modules = (args[0] && typeof args[0] === 'string' ? args : args[0])
, i;
if (!(this instanceof Sandbox)) {
return new Sandbox(modules, callback);
}
if (!modules || modules[0] === '*') {
modules = [];
for (i in Sandbox.modules) {
if (Sandbox.modules.hasOwnProperty(i)) {
modules.push(i);
}
}
}
for (i = 0; i < modules.length; i++) {
Sandbox.modules[modules[i]](this);
}
this.core = {
'exp': {
'classParser': function (name) {
return (new RegExp("(^| )" + name + "( |$)"));
},
'getParser': /^(#|\.)?([\w\-]+)$/
},
'typeOf': typeOf,
'hasOwnProperty': function (obj, prop) {
return obj.hasOwnProperty(prop);
},
'forEach': function (arr, fn, scope) {
scope = scope || config.win;
for (var i = 0, j = arr.length; i < j; i++) {
fn.call(scope, arr[i], i, arr);
}
}
};
this.config = {
'win' : win,
'doc' : doc
};
callback(this);
}
如何从 this.core.forEach 中访问 this.config.win?或者这不可能?
【问题讨论】:
标签: javascript object reference