mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 02:17:50 +00:00
testing bind without context
This commit is contained in:
@@ -4,13 +4,16 @@ $(document).ready(function() {
|
|||||||
|
|
||||||
test("functions: bind", function() {
|
test("functions: bind", function() {
|
||||||
var context = {name : 'moe'};
|
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);
|
var bound = _.bind(func, context);
|
||||||
equals(bound(), 'name: moe', 'can bind a function to a context');
|
equals(bound(), 'name: moe', 'can bind a function to a context');
|
||||||
|
|
||||||
bound = _(func).bind(context);
|
bound = _(func).bind(context);
|
||||||
equals(bound(), 'name: moe', 'can do OO-style binding');
|
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 = function(salutation, name) { return salutation + ': ' + name; };
|
||||||
func = _.bind(func, this, 'hello');
|
func = _.bind(func, this, 'hello');
|
||||||
equals(func('moe'), 'hello: moe', 'the function was partially applied in advance');
|
equals(func('moe'), 'hello: moe', 'the function was partially applied in advance');
|
||||||
|
|||||||
Reference in New Issue
Block a user