Yes, chrome.storage
is an Object, chrome.storage.type
is a property on the object chrome.storage
which does not exists and therefor will be undefined.
Can a variable be both an object and undefined at the same time?
-
15-07-2023 - |
题
I'm mocking chrome.storage
using jasmine's spyOn
function like this:
this.fakeChromeStorage = {};
chrome = { storage: { sync: {get: function() {}, set: function() {}}}};
spyOn(chrome.storage.sync, 'get').and.callFake(function(key, callback) {
callback();
});
But then when my application calls:
console.info(chrome.storage);
console.info(typeof chrome.storage);
console.info(chrome.storage.type);
console.info(typeof chrome.storage.type);
It prints:
[object Object]
object
undefined
undefined
How is this even possible?
解决方案
不隶属于 StackOverflow