en.javascript.info/1-js/6-objects-more/1-object-methods/4-object-property-this/solution.md
Ilya Kantor 87bf53d076 update
2014-11-16 01:40:20 +03:00

22 lines
880 B
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.

**Ответ: пустая строка.**
```js
//+ run
var name = "";
var user = {
name: "Василий",
*!*
export: this // (*)
*/!*
};
alert(user.export.name);
```
Объявление объекта само по себе не влияет на `this`. Никаких функций, которые могли бы повлиять на контекст, здесь нет.
Так как код находится вообще вне любых функций, то `this` в нём равен `window` (при `use strict` было бы `undefined`).
Получается, что в строке `(*)` мы имеем `export: window`, так что далее `alert(user.export.name)` выводит свойство `window.name`, то есть глобальную переменную `name`, которая равна пустой строке.