问题描述
=http://c2.com/cgi/wiki?ClosuresAndObjectsAreEquivalent =nofollow noreferrer>在 (),但我不太明白这是什么意思。有人可以解释一下它是什么意思?
I have seen this statement at many places on the web (including SO) but I don't quite understand what it means. Could someone please explain what it exactly means?
如果可能,请在答案中包含示例。
If possible, please include examples in your answer.
推荐答案
考虑Java。 Java是一种面向对象的编程语言,没有语言级支持真正的词汇闭包。作为一个工作的Java程序员使用匿名内部类,可以关闭词法作用域中的可用变量(前提是它们 final
)。
Consider Java. Java is an object-oriented programming language with no language level support for real lexical closures. As a work-around Java programmers use anonymous inner classes that can close over the variables available in lexical scope (provided they're final
). In this sense, objects are poor man's closures.
Consider Haskell. Haskell is a functional language with no language level support for real objects. However they can be modeled using closures, as described in this excellent paper by Oleg Kiselyov and Ralf Lammel. In this sense, closures are poor man's objects.
如果你来自OO背景,在对象更加自然,因此可能因此认为它们是一个比封闭更基本的概念。如果你来自FP背景,你可能会发现,关闭的思维更自然,因此可能认为它们是一个比对象更基本的概念。
If you come from an OO background, you'll probably find thinking in terms of objects more natural, and may therefore think of them as a more fundamental concept than closures. If you come from a FP background, you might find thinking in terms of closures more natural, and may therefore think of them as a more fundamental concept than objects.
故事的道德是,闭包和对象是彼此可表达的想法,没有一个比另一个更基本 。
在哲学中,这被称为。
这篇关于“闭合是穷人的对象,反之亦然” - 这是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!