an observer manages a callback function
you can call the method via the monster namespace new Monster.Types.Observer()
.
<script type="module">
import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.6.0/dist/modules/types/observer.js';
console.log(new Monster.Types.Observer())
</script>
Alternatively, you can also integrate this function individually.
<script type="module">
import {Observer} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.6.0/dist/modules/types/observer.js';
console.log(Observer())
</script>
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.
<script>
Observer(()=>{
// this is not subject
})
Observer(function() {
// this is subject
})
</script>
additional arguments can be passed to the callback. to do this, simply specify them.
<script>
Observer(function(a, b, c) {
console.log(a, b, c); // ↦ "a", 2, true
}, "a", 2, true)
</script>
the callback function must have as many parameters as arguments are given.