This commit is contained in:
Ilya Kantor 2017-08-22 23:19:09 +02:00
parent 25e97bb50e
commit 468a769b51
3 changed files with 5 additions and 6 deletions

View file

@ -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. 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.

View file

@ -1,11 +1,10 @@
Just loop over the object and `return false` immediately if there's at least one property. Just loop over the object and `return false` immediately if there's at least one property.
```js ```js
function isEmpty(obj) function isEmpty(obj) {
for(let key in obj) { for(let key in obj) {
return false; return false;
} }
return true; return true;
} }
``` ```

View file

@ -233,12 +233,11 @@ In real code we often use existing variables as values for property names.
For instance: For instance:
```js run ```js run
function makeUser() { function makeUser(name, age) {
let name = prompt("Name?");
let age = prompt("Age?");
return { return {
name: name, name: name,
age: age age: age
// ...other properties
}; };
} }
@ -256,6 +255,7 @@ function makeUser(name, age) {
return { return {
name, // same as name: name name, // same as name: name
age // same as age: age age // same as age: age
// ...
}; };
*/!* */!*
} }