No, it does not. I could make no sense of your post...
Begging your pardon.
Here is a clean-up.
// When global 'Hash' variable has a value,
// save it in local '_Hash' variable.
if(typeof window.Hash != 'undefined') {
var _Hash = window.Hash;
}
// Define function and store it both in a local variable
// and in a global variable named 'Hash'
var Hash = window.Hash = function(args) {
// Check if 'Hash' is being called with the 'new' operator.
if(this instanceof arguments.callee) {
// Run the 'init' method on the current object.
// The method should have been defined elsewhere!
this.init.apply(this, args && args.callee ? args : arguments);
} else {
// Make sure the 'new' operator is used
// and return its result.
return new Hash(arguments);
}
};
The meaning of the ternary expression, which supplies the argument to
'init' is very *deep*.
(1) When we are in an original call to 'new Hash(something)', then
args==something, so that 'arguments' is passed, which amounts to
passing 'something', which is ok.
(2) When we are in a redirected call which originally was just 'Hash
(something)'
then 'args' is the original 'arguments', and thus 'args.callee' is
defined,
so that the original arguments are passed to 'init', which is ok
again.
In sum:
the above construction makes sure that 'Hash' can both be called with
the 'new' operator or without,
having the same intended result in both cases.
Example:
Hash.prototype.init = function( a, b ) {
this.a = a;
this.b = b;
};
Hash.prototype.toString = function() {
return "[object Hash: a=" + this.a + ", b=" + this.b + "]";
}
function test() {
alert( new Hash( 1, 2 ) );
alert( Hash( 10, 20 ) );
}