Firefox SDK端口发送功能 [英] Firefox SDK port sending functions

查看:98
本文介绍了Firefox SDK端口发送功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我试图通过port.emit发送一个函数时,它会在另一边结束。如果我把它改为一个简单的字符串,它工作正常。你可以不发送函数抛出?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆