Skip to content

Commit a34c4a7

Browse files
committed
Complete about_this
1 parent 96900f5 commit a34c4a7

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

topics/about_this.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ test("'this' inside a method", function () {
44
var person = {
55
name: 'bob',
66
intro: function () {
7-
return "Hello, my name is " + this.__;
8-
}
7+
return "Hello, my name is " + this.name;
8+
}
99
}
1010
equal(person.intro(), "Hello, my name is bob", "If an object has a method can you access properties inside it?");
1111
});
@@ -15,14 +15,14 @@ test("'this' on unattached function", function () {
1515
globalName: 'bob',
1616
intro: function () {
1717
return "Hello, my name is " + this.globalName;
18-
}
18+
}
1919
}
2020

2121
var alias = person.intro;
22-
23-
// if the function is not called as an object property 'this' is the global context
22+
23+
// if the function is not called as an object property 'this' is the global context
2424
// (window in a browser). This is an example. Please do not do this in practise.
25-
window.__ = 'Peter';
25+
window.globalName = 'Peter';
2626
equal(alias(), "Hello, my name is Peter", "What does 'this' referer to when it is not part of an object?");
2727
});
2828

@@ -31,11 +31,11 @@ test("'this' set explicitly", function () {
3131
name: 'bob',
3232
intro: function () {
3333
return "Hello, my name is " + this.name;
34-
}
34+
}
3535
}
3636

3737
// calling a function with 'call' lets us assign 'this' explicitly
38-
var message = person.intro.call({__: "Frank"});
38+
var message = person.intro.call({name: "Frank"});
3939
equal(message, "Hello, my name is Frank", "What does 'this' referer to when you use the 'call()' method?");
4040
});
4141

0 commit comments

Comments
 (0)