【发布时间】:2014-05-04 17:42:49
【问题描述】:
我正在使用 jasmine 的 spyOn 函数模拟 chrome.storage,如下所示:
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是一个具有未定义type属性的对象?我不确定这有什么令人困惑的地方。 -
它令人困惑,因为我认为
.type是你表达typeof的方式 -
一点也不。
typeof是唯一计算类型的东西。.type这里只是一个随机属性。
标签: javascript gruntjs jasmine phantomjs