如何从继承的静态方法访问继承的静态属性?

时间:2017-07-26 22:20:27

标签: javascript node.js ecmascript-6

我有一个超类Foo,它有一个静态方法和一个实例方法,它们都是console.log()一个静态属性。

如何让静态方法对属性引用正确的静态属性。正如您在此处所看到的,它只引用了超类属性而不是子类属性。

<select id="recommended_food"   multiple="multiple" size=3 style='height: 100%;' name="recommended_food[]">
    @if ($food->recomemded_food)
      {{ ($val = 'Fries')
        && $chosen = in_array($val, $food->recommended_food)
        ? 'selected':null}}
      <option value="{{$val}}" {{$chosen}}>{{$val}}</option>
      {{ ($val = 'Hot Dogs')
        && $chosen = in_array($val, $food->recommended_food)
        ? 'selected':null}}
      <option value="{{$val}}" {{$chosen}}>{{$val}}</option>
      {{ ($val = 'Hamburgers')
        && $chosen = in_array($val, $food->recommended_food)
        ? 'selected':null}}
      <option value="{{$val}}" {{$chosen}}>{{$val}}</option>
    @endif
  </select>

预期产出:

class Foo{
    whoAmI(){
        console.log(this.constructor.someStaticVar)
    }
    static whoAmI_static(){
        console.log(Foo.someStaticVar) // is there a way to call the calling class and not the superclass here?
    }
}
Foo.someStaticVar = 'I am Foo'


class Bar extends Foo{

}
Bar.someStaticVar = 'I am Bar'



let barInstance = new Bar()
Bar.whoAmI_static()
barInstance.whoAmI()

实际输出:

I am Bar
I am Bar

0 个答案:

没有答案