Skip to content

Commit e6243c9

Browse files
committed
[naming conventions] saving reference to this, use _this. fixes airbnb#32
1 parent d521014 commit e6243c9

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,34 @@
954954
this._firstName = 'Panda';
955955
```
956956

957+
- When saving a reference to `this` use `_this`.
958+
959+
```javascript
960+
// bad
961+
function() {
962+
var self = this;
963+
return function() {
964+
console.log(self);
965+
};
966+
}
967+
968+
// bad
969+
function() {
970+
var that = this;
971+
return function() {
972+
console.log(that);
973+
};
974+
}
975+
976+
// good
977+
function() {
978+
var _this = this;
979+
return function() {
980+
console.log(_this);
981+
};
982+
}
983+
```
984+
957985
- Name your functions. This is helpful for stack traces.
958986

959987
```javascript

0 commit comments

Comments
 (0)