Firstly arguments.callee
is deprecated in ES5 strict so we don't use it. The real solution is rather simple.
You don't use new
at all.
var Make = function () {
if (Object.getPrototypeOf(this) !== Make.prototype) {
var o = Object.create(Make.prototype);
o.constructor.apply(o, arguments);
return o;
}
...
}
That's a right pain in the ass right?
Try enhance
var Make = enhance(function () {
...
});
var enhance = function (constr) {
return function () {
if (Object.getPrototypeOf(this) !== constr.prototype) {
var o = Object.create(constr.prototype);
constr.apply(o, arguments);
return o;
}
return constr.apply(this, arguments);
}
}
Now of course this requires ES5, but everyone uses the ES5-shim right?
You may also be interested in alternative js OO patterns
As an aside you can replace option two with
var Make = function () {
var that = Object.create(Make.prototype);
// use that
return that;
}
In case you want your own ES5 Object.create
shim then it's really easy
Object.create = function (proto) {
var dummy = function () {};
dummy.prototype = proto;
return new dummy;
};
SignalR has a JavaScript API. SignalR helps build asynchronous scalable web applications with real-time persistent long-running connections. Scott Hanselman wrote a great blog post about this.
If that's not your speed, you may be looking for something more like WCF Support for jQuery, which seems to have sprung up from the old WCF-RIA jQuery client. Looks like this will be part of ASP.NET MVC 4. The wiki page for this project seems to indicate that its flexible enough to plug in to WebSockets.
I'm a little concerned about WebSockets in the near term. There are some questions about just how Internet infrastructure (particularly in corporate environments where proxy servers are common) will handle WebSockets. I believe SignalR has strategies to help mitigate this by negotiating fallbacks when WebSockets don't work. Scott Hanselman has another blog post about this which makes some good points in this direction.
Best Answer
It also helps to speed up the library as
window
ordocument
is now locally bound. And this also ensures that if latter the user, replaces thewindow
object with say:window = "Help, I'm trapped in a window overwriting assignment statement.";
; the library continues to work.