function $() { if (this.constructor != $) { return new $; } } $.x = 1; $.prototype.y = 2; $.prototype.f = function () { alert([this.constructor.x, this.y]); }; $().f();