user1670407
user1670407

Reputation:

Is it possible to send functions through the Firefox SDK's port.emit()?

When I trying to send a function through port.emit it ends up null on the other side. If I change it to a simple string it works fine. Can you not send functions through emit?

self.port.emit("requestBackground", someFunction);

Upvotes: 1

Views: 66

Answers (1)

Makyen
Makyen

Reputation: 33376

A quick look at the documentation for port.emit() indicates:

It may be called with any number of parameters, but is most likely to be called with a name for the message and an optional payload. The payload can be any value that is serializable to JSON.

Clicking on the link about it being serializable to JSON would have told you:

However, you do have to ensure that the payload can be serialized to JSON. This means that it needs to be a string, number, boolean, null, array of JSON-serializable values, or an object whose property values are themselves JSON-serializable. This means you can't send functions, and if the object contains methods they won't be encoded.

Upvotes: 1

Related Questions