I have an object like this:
function A(id) {
this.id = id;
}
A.prototype.getId = function() {
return this.id;
}
It is included in the html page as a file ("objects.js"), as well as in a web worker with importScript ("objects.js"). Now I create an instance of A on the html page using "var a = new A ()" and send it using "postMessage ()" to the web worker.
The funny thing is that the employee still has the "id" property with its value, but the prototype function is lost. I think the reason may be that the prototype functions are “tied” to the context of the html page, and not to the context of the web worker.
So what I do in a worker is:
event.data.a.__proto__ = A.prototype;
It works, and I see it as a kind of casting ...
, , -.
...