On 10/5/16, 11:13 AM, "Harbs" <harbs.li...@gmail.com> wrote:

>And what’s the reason we’re not just using Foo.someOtherStaticProperty?
>Is this a getter issue?

Getters/Setters need to be defined via Object.defineProperty.  It is the
only way to access a function via a property name (without using
parentheses).  IOW

  function Foo() {}  // defines the class

  Foo.someMethod = function() // defines a method.

  Foo.someVar; // defines a var or const.

But when you use them, you have to write:

  Foo.someMethod()  // note the parenthesis for function call

Or

  Foo.someVar // but no function will be called.

We want getters and setters to be accessed like:

  Foo.someGetter; // calls a function

instead of:

  Foo.someGetter();

So, we create an Object.defineProperties structure that looks like:

{ someGetter: { get: // the code that would run }}

Once you do that, when scanning Foo for vars and methods, GCC will not see
these getters and setters so it will not think that Foo has a someGetter
property.  GCC is only looking for the pattern of Foo.someMethod =
function and Foo.someVar = initialValue;

So then when you use someGetter as

  var value = Foo.someGetter;

GCC just renames it to a global like:

  var value = xx;

And thus, the someGetter code is never called.

HTH,
-Alex

Reply via email to