static/class properties

Dmitry Soshnikov dmitry.soshnikov at gmail.com
Thu Sep 19 01:16:58 PDT 2013


Hi,

Out of curiosity: we have static methods, but seems there is no yet ability to define a class/static property/constant.

class A {
  const VALUE = 10;
}

or (probably better to be consistent with static methods):

class A {
  static VALUE = 10;
}

Was it a special reason or was it just forgotten? (One could define a var in the static scope, but seems it's useful to have the feature inline in the class bodies).

P.S.: in addition -- why not to reuse `static` for also simple functions?

function getHeavyValue() {
  static heavyValue;
  if (!heavyValue) {
    // heavy calc
  }
  return heavyValue;
}

Dmitry


More information about the es-discuss mailing list