Suppose I have an object X defined as
var X = function () {}; X.prototype.doSomething = function () {}; X.prototype.doSomethingElse = function () {};
Is it possible to build a function f so that f instanceof X ? Note that I should also be able to f() without TypeError .
In Mozilla, I can do what I want with __proto__ :
var f = function () {}; f.__proto__ = new X;
However, this is (1) non-standard and (2) outdated. The MDN page for __proto__ suggests using Object.getPrototypeOf instead, but what I'm really looking for is Object.setPrototypeOf (which does not exist, although the idea is brought up in this error report ).
Cheap approximation to what I want
var f = function () {}; jQuery.extend(f, new X);
Unfortunately, this does not make f instanceof X true (and I will not expect this!).
javascript
Snowball Jun 12 '12 at 19:05 2012-06-12 19:05
source share