Skip to content

Commit 329b8ca

Browse files
committed
Merge branch 'bsr_newtests'
2 parents 8983e02 + 051c570 commit 329b8ca

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

topics/about_asserts.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
module("About Asserts (topics/about_asserts.js)");
33

44
test("ok", function() {
5-
ok(false, 'what will satisfy the ok assertion?');
5+
ok(__, 'what will satisfy the ok assertion?');
66
});
77

88
test("not", function() {

topics/about_functions_and_closure.js

+28
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,31 @@ test("arguments array", function() {
4545
equals(add(1,2,3,4,5), 15, "add 1,2,3,4,5");
4646
equals(add(4,7,-2), 9, "add 1,2,3,4,5");
4747
});
48+
49+
test("using call to invoke function",function(){
50+
var invokee = function( message ){
51+
return this + message;
52+
};
53+
54+
//another way to invoke a function is to use the call function which allows
55+
//you to set the callers "this" context. Call can take any number of arguments:
56+
//the first one is always the context that this should be set to in the called
57+
//function, and the arguments to be sent to the function,multiple arguments are separated by commas.
58+
var result = invokee.call("I am this!", "Where did it come from?");
59+
60+
equals(result,__,"what will the value of invokee's this be?");
61+
});
62+
63+
test("using apply to invoke function",function(){
64+
var invokee = function( message1, message2 ){
65+
return this + message1 + message2;
66+
};
67+
68+
//similar to the call function is the apply function. Apply only has two
69+
//arguments: the first is the context that this should be set to in the called
70+
//function and and array of arguments to be passed into the called function.
71+
var result = invokee.apply("I am this!", ["I am arg1","I am arg2"]);
72+
73+
equals(result,__,"what will the value of invokee's this be?");
74+
});
75+

0 commit comments

Comments
 (0)