Skip to content

Commit

Permalink
testing bind without context
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed Nov 8, 2009
1 parent ef35fe1 commit 9d4e34e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions test/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 9d4e34e

Please sign in to comment.