Files
freeCodeCamp/guide/russian/javascript/with/index.md
Randell Dawson 0a1eeea424 fix(guide) Replace invalid prism code block names (#35961)
* fix: replace sh with shell

fix replace terminal with shell

fix replace node with js

fix replace output with shell

fix replace cs with csharp

fix replace c++ with cpp

fix replace c# with csharp

fix replace javasctipt with js

fix replace syntax  with js

fix replace unix with shell

fix replace linux with shell

fix replace java 8 with java

fix replace swift4 with swift

fix replace react.js with jsx

fix replace javascriot with js

fix replace javacsript with js

fix replace c++ -  with cpp

fix: corrected various typos

fix: replace Algorithm with nothing

fix: replace xaml with xml

fix: replace solidity with nothing

fix: replace c++ with cpp

fix: replace txt with shell

fix: replace code with json and css

fix: replace console with shell
2019-05-15 19:08:19 +02:00

75 lines
2.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: With
localeTitle: С
---
## С
Оператор JavaScript `with` выражением является сокращенным способом редактирования нескольких свойств на одном объекте. Большинство разработчиков отговорить использование `with` , и вы лучше не использовать это ключевое слово.
**Примечание** : `"strict mode"` запрещает использование `with` .
### Синтаксис
```js
with (expression)
statement
```
### Пример использования
В JavaScript вы можете индивидуально изменять свойства объекта, как показано ниже:
```javascript
let earth = {};
earth.moons = 1;
earth.continents = 7;
```
`with` дает вам стенографию для изменения свойств объекта:
```javascript
with (earth) {
moons = 1;
continents = 7;
}
```
Хотя этот пример надуман, вы можете понять примеры использования `with` большим количеством, если у вас есть более крупные объекты, например:
```javascript
earth.continents.australia.geography.ocean = "Pacific";
earth.continents.australia.geography.river = "Murray";
earth.continents.australia.geography.mountain = "Kosciuszko";
```
### альтернативы
Вы не должны использовать `with` , как это имеет тонкие ошибки и проблемы совместимости. Очень рекомендуемый подход - назначить объект переменной, а затем изменить свойства переменной. Вот пример использования более крупного объекта:
```javascript
let earth = {
continents: {
australia: {
geography: {}
}
}
};
let geo = earth.continents.australia.geography;
geo.ocean = "Pacific";
geo.river = "Murray";
geo.mountain = "Kosciuszko";
```
### Попробовать
https://repl.it/Mixg/5
#### Дополнительная информация:
[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/with](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/with)
[https://yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/](https://yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/)
[http://2ality.com/2011/06/with-statement.html](http://2ality.com/2011/06/with-statement.html)