Alex,

I think what you're seeing is an artifact of the way you've set up
your example... You don't instantiate the object and never reference
the property outside of the class' internals. WIth such a minimal
case, that basically doesn't execute, the compiler thinks it can be
smart and 'optimize' away vital parts of the code... If I rework your
example a bit to make it feel more 'real world' to the compiler:



/**
 * @constructor
 */
var org_apache_flex_utils_BinaryData = function () {

  /**
   * @private {number}
   */
  this.productService_;

}

org_apache_flex_utils_BinaryData.prototype.someFunction = function() {
  console.log(this.productService);
};

Object.defineProperties(org_apache_flex_utils_BinaryData.prototype, {
  productService: {
    /** @this {org_apache_flex_utils_BinaryData} */
    get: function() {
      return this.productService_;
    },
    /** @this {org_apache_flex_utils_BinaryData} */
    set: function(value) {
      this.productService_ = value + 10;
    }
  }
});

var binaryData = new org_apache_flex_utils_BinaryData();

binaryData.productService = 100;

binaryData.someFunction();



... You get, without errors or warnings:



'use strict';function
a(){}Object.defineProperties(a.prototype,{a:{get:function(){return
this.b},set:function(c){this.b=c+10}}});var b=new
a;b.a=100;console.log(b.a);



This code does actually execute and it gives the expected 110, showing
the setter is called and the 'defineProperties' is not simply ignored.
You see the property is renamed to the same string 'everywhere', so
the compiler knows what it is and how to handle it.

In this example you can prevent the renaming by declaring the property
with an @expose annotation on the object's prototype just before
calling 'Object.defineProperties':



/**
 * @expose
 */
org_apache_flex_utils_BinaryData.prototype.productService;



Which, combined, gives a compiled output:



'use strict';function
a(){}Object.defineProperties(a.prototype,{productService:{get:function(){return
this.a},set:function(c){this.a=c+10}}});var b=new
a;b.productService=100;console.log(b.productService);



Isn't that what you're looking for?

EdB



-- 
Ix Multimedia Software

Jan Luykenstraat 27
3521 VB Utrecht

T. 06-51952295
I. www.ixsoftware.nl

Reply via email to