Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement angular $watch function in core javascript

As i know that angular watches are evaluated in every digest loop. So, i need such kind of function in core javascript for watch http response json object.

Somethings like this:-

var oldResponseData='{"name":"Ram","age":"45"}';
function myCustomeWatch(httpResponseData){
  if(httpResponseData===oldResponseData){
     return false;
  }else{
     oldResponseData=httpResponseData;
  }
}
.
.
.
 httpResponseData='{"name":"Ram","age":"46"}';//'{"name":"Ram","age":"45"}' != '{"name":"Ram","age":"46"}'
setInterval(function(){
   myCustomeWatch(httpResponseData);
},3000);
like image 473
vineet Avatar asked Jan 27 '26 00:01

vineet


1 Answers

You can also use Object.watch. More info is available here

And here is the polyfill for ES5 compatible browsers

like image 67
Narendra CM Avatar answered Jan 28 '26 13:01

Narendra CM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!