[英]Can a variable be both an object and undefined at the same time?
我嘲笑chrome.storage
使用茉莉的spyOn
功能如下:
this.fakeChromeStorage = {};
chrome = { storage: { sync: {get: function() {}, set: function() {}}}};
spyOn(chrome.storage.sync, 'get').and.callFake(function(key, callback) {
callback();
});
但是当我的应用程序调用时:
console.info(chrome.storage);
console.info(typeof chrome.storage);
console.info(chrome.storage.type);
console.info(typeof chrome.storage.type);
它打印:
[object Object]
object
undefined
undefined
这怎么可能?
是的, chrome.storage
是一个对象, chrome.storage.type
是在对象的属性chrome.storage
它不存在,并为此将是不确定的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.