Yup, you're wrong on two counts:You want to pass the function b itself to call(), not the return value of the function, so those brackets shouldn't be there. Then, this in that scope refers to the global object. I think you've misunderstood its purpose: it refers to the object as a property of which the function was called, not the function itself. E.G.:
Code:
var a = {
b: {
c: function() {
// here, this refers to a.b, not a.b.c.
}
}
};
No. Adding properties to a function object doesn't create them as variables within the function's scope.
Is what I'm trying to accomplish strictly impossible?
As far as I'm aware.
If I defined Import to return a string, I could do eval(Import("script.js")), but I want to make it so you only have to manually call one function.
That's ugly. In fact, the original Import() idea was ugly too. The neat solution is to have import() (without a capital, since that's reserved for constructors) return an object, which acts both as a convenient container for the multiple return values and a namespace for the calling function.
Bookmarks