简体   繁体   中英

Javascript OOP calling object functions (getUserMedia)


I have a problem with my javascript code since I started changing it to an OOP approach. I want to create an Object class with many class functions within and the class functions should be able to call each other. But this is not working. Here is a (simpified) code snippet:

function MyClass(){
    this.someClassVariable = false;
    this.anotherClassVariable = 10;
}

MyClass.prototype = {
    constructor: MyClass,

   firstFunction:function(){
       if (this.someClassVariable == false){
           this.secondFunction();
       }
   },

   secondFunction:function(){
       while(this.anotherClassVariable != 0){
           this.anotherClassVariable--;
           console.log(this.anotherClassVariable);
       }
   }
}

var myClass = new MyClass();
navigator.getUserMedia({audio: true}, myClass.firstFunction, function(e) {});

This always gets me the the error

Uncaught TypeError: __tracer.traceFunCall(...) is not a function

But when I call the Class and Function without getUserMedia() like this:

var myClass = new MyClass();
myClass.firstFunction();

it works.
Am I missing something? Would be really glad if someone could give me a hint, searched a lot for this specific topic but didn't find anything.

Thanks!

试用

navigator.getUserMedia({audio: true}, myClass.firstFunction.bind(myClass), function(e) {});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM