diff --git a/spec/stdlib/underscore-extensions-spec.coffee b/spec/stdlib/underscore-extensions-spec.coffee index 2c2b1ceac..ee12f269e 100644 --- a/spec/stdlib/underscore-extensions-spec.coffee +++ b/spec/stdlib/underscore-extensions-spec.coffee @@ -8,13 +8,13 @@ describe "underscore extensions", -> calls = [] object = { method: (args...) -> - calls.push(["original", args]) + calls.push(["original", this, args]) } it "calls the given function before the advised method", -> - _.adviseBefore object, 'method', (args...) -> calls.push(["advice", args]) + _.adviseBefore object, 'method', (args...) -> calls.push(["advice", this, args]) object.method(1, 2, 3) - expect(calls).toEqual [['advice', [1, 2, 3]], ['original', [1, 2, 3]]] + expect(calls).toEqual [['advice', object, [1, 2, 3]], ['original', object, [1, 2, 3]]] it "cancels the original method's invocation if the advice returns true", -> _.adviseBefore object, 'method', -> false diff --git a/src/stdlib/underscore-extensions.coffee b/src/stdlib/underscore-extensions.coffee index adbda8861..1fda906ee 100644 --- a/src/stdlib/underscore-extensions.coffee +++ b/src/stdlib/underscore-extensions.coffee @@ -13,8 +13,8 @@ _.mixin adviseBefore: (object, methodName, advice) -> original = object[methodName] object[methodName] = (args...) -> - unless advice(args...) == false - original(args...) + unless advice.apply(this, args) == false + original.apply(this, args) escapeRegExp: (string) -> # Referring to the table here: