亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

javascript - How to bind a callback function to a variable
高洛峰
高洛峰 2017-06-26 10:53:29
0
3
1038

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.

高洛峰
高洛峰

擁有18年軟件開發(fā)和IT教學經驗。曾任多家上市公司技術總監(jiān)、架構師、項目經理、高級軟件工程師等職務。 網絡人氣名人講師,...

reply all(3)
迷茫

var test = {
_age : 0,
methods:function(a)
{

console.log("發(fā)生變化了值為:"+a);

},
//_Age reading and writing
set age(age) {

if(age!=this._age)
{
    this.methods(age);
    this._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.

var obj = {
        set: function (key, value) {
            if(['set', 'change'].indexOf(key) > -1) return;

            this[key] = value;

            this.change();
        },

    };

    obj.change = function(){
        alert(1)
        console.log(this);
    }

    obj.set('name', 'segmentfault');
    
     // 將你需要的變量設為obj的一個屬性
     // 更改變量用obj.set()這個方法
淡淡煙草味

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template