Skip to content
This repository was archived by the owner on Sep 12, 2022. It is now read-only.

Commit 2dc6bef

Browse files
committed
Merge pull request #8 from mbst/fix-for-referencing-scope
Updated example as it was incorrect
2 parents 61ad77a + 611fe86 commit 2dc6bef

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,11 +1266,18 @@ age > 18 ? location.assign("continue.html") : stop = true;
12661266
12671267
// good
12681268
function() {
1269-
var _this = this;
1269+
var self = this;
12701270
return function() {
1271-
console.log(_this);
1271+
console.log(self);
12721272
};
12731273
}
1274+
1275+
// better
1276+
function () {
1277+
return function() {}
1278+
console.log(this);
1279+
}.bind(this);
1280+
}
12741281
```
12751282

12761283
- Name your functions. This is helpful for stack traces.

0 commit comments

Comments
 (0)