fixes
This commit is contained in:
parent
25e97bb50e
commit
468a769b51
3 changed files with 5 additions and 6 deletions
|
@ -1,4 +1,4 @@
|
|||
# How to write bad code?
|
||||
# Ninja code
|
||||
|
||||
Programmer ninjas of the past used these tricks to make code maintainers cry. Code review gurus look for them in test tasks. Novice developers sometimes use them even better than programmer ninjas.
|
||||
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
Just loop over the object and `return false` immediately if there's at least one property.
|
||||
|
||||
```js
|
||||
function isEmpty(obj)
|
||||
function isEmpty(obj) {
|
||||
for(let key in obj) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -233,12 +233,11 @@ In real code we often use existing variables as values for property names.
|
|||
For instance:
|
||||
|
||||
```js run
|
||||
function makeUser() {
|
||||
let name = prompt("Name?");
|
||||
let age = prompt("Age?");
|
||||
function makeUser(name, age) {
|
||||
return {
|
||||
name: name,
|
||||
age: age
|
||||
// ...other properties
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -256,6 +255,7 @@ function makeUser(name, age) {
|
|||
return {
|
||||
name, // same as name: name
|
||||
age // same as age: age
|
||||
// ...
|
||||
};
|
||||
*/!*
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue