-1
訪問類考慮下面的類:的JavaScript:從MutationObserver
function MyCustomClass(e){
this.element = e;
this.start(){
var observer = new MutationObserver(this.mutationObserved),
config = {
attributes: true
};
observer.observe(this.element, config);
}
this.anotherFunction = function(){
console.log("Another function was called");
}
this.mutationObserved = function(e){
// This doesn't work
this.anotherFunction();
}
}
如何訪問其中mutationObserved
類操作類?
this.anotherFunction
不起作用,因爲範圍現在在MutationObserver
類中。
['Function.prototype.bind'](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind) – Andreas