Groovy: значение «это» внутри замыкания

Я решил работать над парсером, основанным на событиях.

EDIT:

Я, наконец, разработал версию синтаксического анализатора, которая Я доволен. Он доступен на GitHub:

https://github.com/kuma-giyomu/JSONParser

Там, вероятно, есть место для некоторого улучшения и приветствуются отзывы.

10
задан Jason S 5 January 2010 в 22:02
поделиться

1 ответ

Взгляните на страницу 144

... это относится к закрытию, а не к the declaring object. At this point, closures play a trick for us. They delegate all method calls to a so-called delegate object, which by default happends to be the declaring object (that is, the owner). This make the closure appear as if the enclosed code runs in the birthday context.

For your questions;

this inside a closure evaluates to the scope in which the closure is called?

from the book they state that "this refer to the closure, not to the declaring object" Но из bertport и моего эксперимента кажется, что «this» на самом деле является декларирующим объектом.

В любом случае, ответ на ваш вопрос по-прежнему «no».

в закрытии, показанном выше, this и caller ссылаются на тот же объем?

Боюсь, что нет.

Имейте в виду, что страницы 143 и 144 в Groovy in Action нуждаются в некоторых исправлениях

http://groovy.canoo.com/errata/erratum/show/5

http://groovy.canoo.com/errata/erratum/show/8

9
ответ дан 3 December 2019 в 16:30
поделиться
Другие вопросы по тегам:

Похожие вопросы: