1
全部;茉莉花間諜如何工作
我剛開始學習茉莉花(2.0.3版本),當我到間諜節,第一個例子讓我感到困惑:
describe("A spy", function() {
var foo, bar = null;
beforeEach(function() {
foo = {
setBar: function(value) {
bar = value;
}
};
spyOn(foo, 'setBar');
foo.setBar(123);
foo.setBar(456, 'another param');
});
it("tracks that the spy was called", function() {
expect(foo.setBar).toHaveBeenCalled();
});
it("tracks all the arguments of its calls", function() {
expect(foo.setBar).toHaveBeenCalledWith(123);
expect(foo.setBar).toHaveBeenCalledWith(456, 'another param');
});
it("stops all execution on a function", function() {
expect(bar).toBeNull();
});
});
我不知道是否有人能解釋爲什麼setBar功能不影響塊內定義的塊吧?茉莉花間諜如何處理這件事?
謝謝
謝謝,最讓我感興趣的是茉莉花如何實現這一點,而無需運行實際功能並影響變量?基本上它是如何將所有東西都複製到其獨立的範圍內(如果我對此的理解是正確的)?你能給我更詳細的介紹嗎? – Kuan
讓我更新一些更多的信息。 –
謝謝,我閱讀http://www.tutorialspoint.com/design_pattern/proxy_pattern。htm根據我的理解,它基本上是使用一個內部對象來委託一個任務。但我有點想知道如何將我的例子與這種模式聯繫起來。 – Kuan