Passing objects to a web worker

后端 未结 8 1071
心在旅途
心在旅途 2020-11-28 06:19

I\'m trying to pass an object to a web worker through the postMessage function.
This object is a square that has a couple of functions to draw himself on a canvas and so

8条回答
  •  温柔的废话
    2020-11-28 06:46

    The real problem with object and webworkers is with the methods of that objects. A object should not have methods just properties.

    Ex:

    var myClass = function(){
        this.a = 5;
        this.myMethod = function(){}
    }
    var notParseableObject = new myClass();
    
    
    var myClass2 = function(){
        this.a = 5;
    }
    var parseableObject = new myClass2();
    

    The first wont work (with the mentioned error message) with postMessage and the second will work.

提交回复
热议问题