Writing
in.some.namespace.hello.apply(in.some.namespace.hello, some_args]
looks verbose and errorprone.
(In the below I've changed in. to n. because you can't declare a variable called in and I wanted to provide some live examples.)
Three options, none of them really exciting: ;-)
Use with, despite its bad rep and incompatibility with strict mode
Write yourself a utility function
Use a disposable variable and don't mind some really funky-looking syntax
Use with:
with (n.some) {
namespace.hello.apply(namespace, some_args);
}
Slightly less repetition, though there's still some, and you have to use with, which is disallowed in strict mode.
Utility function
Example utility function:
function callWith(obj, name, args) {
return obj[name].apply(obj, args);
}
var n = {
some: {
namespace: {
hello: function(a, b, c) {
alert(this.name + " says " + [a, b, c].join(", "));
},
name: "namespace"
}
}
};
callWith(n.some.namespace, "hello", [1, 2, 3]);
(Be careful doing that if you use a minifier that renames methods, as it probably won't update the string.)
Disposable variable and really funky syntax
I want to be clear that I'm not recommending this, just flagging it up as an option: If you have a variable you keep lying around for this purpose, you can do this:
(o = n.some.namespace, o.hello.apply(o, [1, 2, 3]));
E.g.:
var o;
var n = {
some: {
namespace: {
hello: function(a, b, c) {
alert(this.name + " says " + [a, b, c].join(", "));
},
name: "namespace"
}
}
};
(o = n.some.namespace, o.hello.apply(o, [1, 2, 3]));
Arguably that's an abusage of the comma operator. At the very least. :-)