History: I wanted to create an alias/namespace for navigator.getUserMedia. And in that process, I did the following:
let constraints = {}; // Required for setting device constraints
let _getUserMedia = navigator.getUserMedia.bind(navigator);
// It is necessary to bind to the navigator if one makes an alias out of it.
_getUserMedia(constraints).then(res => console.log(res)).catch(err => console.log(err));
I get the following error: Uncaught TypeError: Failed to execute 'getUserMedia' on 'Navigator': 3 arguments required, but only 1 present.
As we know from docs that getUserMedia accepts callbacks for success and failure, and if someone doesn't pass them, a promise response is returned instead. Why does this not return any promise?
Any help on this weird behaviour explanation is highly appreciated.
I've done this a lot. Just use
and forget about the
.bind()
operation. It's unnecessary.