Thiyagu
Thiyagu

Reputation: 786

Need to trigger event when object has value in javascript

Hi Initially I have created empty javascript object ,

var obj = {}

I have push two different values to object from different function I need to trigger any event when object has value, for example if value pushed to object then I need to trigger any event and I saw object.watch() but it is not suitable for me, I dont know my question is wrong or write anyone suggest me for my problem

Upvotes: 1

Views: 141

Answers (1)

Jonas Wilms
Jonas Wilms

Reputation: 138457

var obj=new Proxy({},{
  set(obj,prop,value){
    alert("setting "+prop+" to "+value);
  }
});

Simply use an ES6 Proxy ( reference)

Upvotes: 1

Related Questions