Suppose I have a Javascript class:
function GeneralClass(a, b, c) { ... }
It is constructed like this:
var g = new GeneralClass(a, b, c);
and I want to create a SpecificClass, which is exactly the same as GeneralClass, but with bound values, a=1 and c=3.
I want to construct this class like this:
var s = new SpecificClass(b);
In other languages, there are several ways to do this:
- I can make SpecificClass inherit GeneralClass, and have the constructor of SpecificClass call that of GeneralClass with the assignment I want.
- I can add a GeneralClass field inside SpecificClass, and delegate all method calls to it.
But I am looking for a shorter and more elegant way to do this in Javascript - a way that will enable me to create many different SpecificClass's on the fly.