javascript - Binding a constructor -


suppose have javascript class:

function generalclass(a, b, c) { ... } 

it constructed this:

var g = new generalclass(a, b, c); 

and want create specificclass, same generalclass, bound values, a=1 , c=3.

i want construct class this:

var s = new specificclass(b); 

in other languages, there several ways this:

  • i can make specificclass inherit generalclass, , have constructor of specificclass call of generalclass assignment want.
  • i can add generalclass field inside specificclass, , delegate method calls it.

but looking shorter , more elegant way in javascript - way enable me create many different specificclass's on fly.

you can make specific function creates generalclass bound parameters.

function generalclass(a, b, c) { ... }  function specific(b) {      var = 1, c = 3;     return new generalclass(a, b, c); }  var s = specific(2); 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -