An observer manages a callback function
You can call the method via the monster namespace new Monster.Types.Observer()
.
import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.30.0/dist/monster.js';
new Monster.Types.Observer()
Alternatively, you can also integrate this function individually.
import {Observer} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.30.0/dist/modules/types/observer.js';
new Observer()
The update method is called with the subject object as this pointer. For this reason the callback should not
be an arrow function, because it gets the this pointer of its own context.
new Observer(()=>{
// this is not subject
})
new Observer(function() {
// this is subject
})
Additional arguments can be passed to the callback. To do this, simply specify them.
Observer(function(a, b, c) {
console.log(a, b, c); // ↦ "a", 2, true
}, "a", 2, true)
The callback function must have as many parameters as arguments are given.