From 9d4e34e19e03654082cff8589903ceaf026c11fc Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Sat, 7 Nov 2009 23:24:12 -0500 Subject: [PATCH] testing bind without context --- test/functions.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/functions.js b/test/functions.js index 80c5cb963..a764d75c0 100644 --- a/test/functions.js +++ b/test/functions.js @@ -4,19 +4,22 @@ $(document).ready(function() { test("functions: bind", function() { var context = {name : 'moe'}; - var func = function() { return "name: " + this.name; }; + var func = function(arg) { return "name: " + (this.name || arg); }; var bound = _.bind(func, context); equals(bound(), 'name: moe', 'can bind a function to a context'); bound = _(func).bind(context); equals(bound(), 'name: moe', 'can do OO-style binding'); + bound = _.bind(func, null, 'curly'); + equals(bound(), 'name: curly', 'can bind without specifying a context'); + func = function(salutation, name) { return salutation + ': ' + name; }; func = _.bind(func, this, 'hello'); equals(func('moe'), 'hello: moe', 'the function was partially applied in advance'); var func = _.bind(func, this, 'curly'); - equals(func(), 'hello: curly', 'the function was completely applied in advance'); + equals(func(), 'hello: curly', 'the function was completely applied in advance'); }); test("functions: bindAll", function() {