1

一段时间以来,我研究Object.observe函数并想知道是否可以将其用作“观察者”来帮助我找到作为更改发起者的函数(带有堆栈跟踪)。请参阅下面的代码片段:

jQuery(function() {
    var struc = {
        a: 0
    };
    var spy = function (info) {
        console.log(info); // gives many details about what was changed, but not who made the change
        console.trace(); // it also doesn't give the information that 'callerFun' was originator of the change
    };
    var callerFun = function () {
        ++struc.a;
    };
    Object.observe(struc, spy);
    jQuery('body').bind('click', callerFun);
});

我怎样才能得到callerFun改变的信息struc

4

0 回答 0