我在 chrome 扩展的内容脚本中使用简单的自定义类型。然后通过 chrome.extension.sendRequest() 将项目数组发送到后台页面。在 bgpage 调试器中显示我的类型的实例没有这些方法。此外,具有未定义值的类型属性也会发生同样的情况。怎么了。
function User(id, holder) {
this.id = id;
var hObj = {};
hObj[holder] = 'undefined'; // this is ok
this.holder = hObj;
this.Result = undefined; // this will be lost
this.Code = undefined; // this will be lost
}
// this will be lost
User.prototype.getFirstHolderType = function() {
for (h in this.holder) {
if (h) return h;
}
return false;
};
// this will be lost
User.prototype.hasHolderType = function(h_type) {
for (h in this.holder) {
if (h_type === h) return true;
}
return false;
};
//...
chrome.extension.sendRequest({id: "users_come", users: users},
function(response) {});