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

13 lines
476 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.

Вызов `arr[2]()` -- это обращение к методу объекта `obj[method]()`, в роли `obj` выступает `arr`, а в роли метода: `2`.
Поэтому, как это бывает при вызове функции как метода, функция `arr[2]` получит `this = arr` и выведет массив:
```js
//+ run
var arr = ["a", "b"];
arr.push( function() { alert(this); } )
arr[2](); // "a","b",function
```