javascript - How to bind a callback function to a variable
高洛峰2017-06-26 10:53:29
0
3
867
Can Javascript bind a callback function to a variable? That is: when the value of this variable changes, the callback function is triggered and the content in the callback function is executed.
var test = {
_age : 0,
methods:function(a)
{
},
//_Age reading and writing
set age(age) {
get age() {return this._age;}
};
You can use the set and get methods of the object to perform the desired results
Cannot be implemented directly.
But it can be achieved in other ways.
js set/get
You can add your logic code in the set method, so that your code will be triggered every time it is modified