Firefox SDK端口发送功能 [英] Firefox SDK port sending functions
问题描述
self.port.emit(requestBackground,someFunction);
快速浏览 port.emit()
表示:
< blockquote>
它可以用任意数量的参数调用,但最有可能的是用消息的名称和可选的有效载荷来调用
。
有效载荷可以是任何值可串行化为JSON 。
点击 $ b可以序列化为JSON : $ b
$ b
但是,您必须确保有效负载可以序列化为
JSON。这意味着它需要是JSON序列化值的字符串,数字,布尔值,空值
数组,或者属性值为
的对象本身是JSON序列化的。 这意味着您不能发送
函数,如果对象包含方法,则不会被编码。
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 throw emit?
self.port.emit("requestBackground", someFunction);
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.
这篇关于Firefox SDK端口发送功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!