JavaScript Object.observe on prototype -


consider code below :

function createfoo() {    var val;      function foo() {}    object.defineproperty(foo.prototype, 'foo', {      get: function () {        return val;      },      set: function (value) {        val = value;         document.write('foo value set : ', value);      }    });      return new foo();  }        var foo = createfoo();    object.observe(foo, function (changes) { document.write(changes); });    foo.foo = 'bar';

why object.observe's handler never fired? can object prototype "observed"?

(please, answers must not suggest use kind of third party library.)

update

please, read comments more information , resolution problem.

this

foo.foo = 'bar'; 

does not modify neither foo object nor prototype observe not report anything.

here version triggers observer on this.val = value; :

function createfoo() {          function foo() {}    object.defineproperty(foo.prototype, 'foo', {      get: function () {        return this.val;      },      set: function (value) {        this.val = value;         document.write('foo value set : ', value);      }    });      return new foo();  }        var foo = createfoo();    object.observe(foo, function (changes) { document.write("<br>observer:", changes); });    foo.foo = 'bar';


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -