I know using Function.prototype.call()
we can write a method that can be used on different objects.
I was trying to understand source code of https://cdn.jsdelivr.net/npm/@mediapipe/control_utils/control_utils.js which is structured like this. I needed to un-minified it to see this code.
(function () {
// code
// code
}.call(this));
This module is getting used like
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/camera_utils/camera_utils.js" crossorigin="anonymous"></script>
</head>
<body>
<video class="input_video"></video>
</body>
</html>
<script>
const videoElement = document.getElementsByClassName('input_video')[0];
const camera = new Camera(videoElement, {
onFrame: async () => {
await someMethod({image: videoElement});
},
width: 320,
height: 240
});
camera.start();
</script>
But what can be the purpose of statement like (function () { // code; }.call(this));
in JavaScript module so const camera = new Camera(arg1, arg2); camera.start();
are working?