gpt4 book ai didi

java - 类(java)和闭包(javascript)之间的区别?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:41:18 25 4
gpt4 key购买 nike

我不明白闭包怎么比类更强大。看起来我可以使用类实现相同的闭包行为。任何帮助将不胜感激

最佳答案

闭包是穷人的对象/对象是穷人的闭包

请参阅:closures and objects

对于懒惰的人:

The venerable master Qc Na waswalking with his student, Anton.Hoping to prompt the master into adiscussion, Anton said "Master, I haveheard that objects are a very goodthing - is this true?" Qc Na lookedpityingly at his student and replied,"Foolish pupil - objects are merely apoor man's closures."

Chastised, Anton took his leave fromhis master and returned to his cell,intent on studying closures. Hecarefully read the entire "Lambda: TheUltimate..." series of papers and itscousins, and implemented a smallScheme interpreter with aclosure-based object system. Helearned much, and looked forward toinforming his master of his progress.

On his next walk with Qc Na, Antonattempted to impress his master bysaying "Master, I have diligentlystudied the matter, and now understandthat objects are truly a poor man'sclosures." Qc Na responded by hittingAnton with his stick, saying "Whenwill you learn? Closures are a poorman's object." At that moment, Antonbecame enlightened.

Anton van Straaten

关于java - 类(java)和闭包(javascript)之间的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/795549/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com