If you don’t need to run a constructor function to make your new object,
you can call Object.create()
:
var a = {a: 1};
// a ---> Object.prototype ---> null
var b = Object.create(a);
// b ---> a ---> Object.prototype ---> null
I think that this is what Douglas Crockford is trying to do
here with versions of
JavaScript that don’t have the relatively new Object.create()
.
If you want your new object to be a kind of class, that is, a constructor function that inherits from some other constructor function, this is a readable way of doing so:
function ChildClass (...) {
// call the parent class constructor to give `this`
// all the properties and methods its parent class has
ParentClass.call(this, ...);
// then code that makes the child different from the parent:
// may well override (some of) what the parent class
// constructor just did
}
ChildClass.prototype = new ParentClass;
These idioms need to be made more complex to work with at least
some jQuery plugins. Perhaps jQuery.proxy()
is all that’s needed.