4 ms·
The expression presented in the parameter list is only evaluated once, and that is when the method is defined. The confusion is that people assume the expressio
by zo1 12y ago
The expression presented in the parameter list is only evaluated once, and that is when the method is defined. The confusion is that people assume the expression is evaluated every time the method is called.
- kyllo 12y agoThe confusion is that people assume the expression is evaluated every time the method is called. Because that's how it works in a lot of other languages, such as Ruby and Javascript.
- zo1 12y agoI doubt that's the only reason. I fell for it myself at first without ever seeing a line of Ruby. It initially feels intuitive, and that's why I think most fall for it.
- ollysb 12y agoI think it's because the arguments are bound when the function is called. It's just natural that you'd expect the default values to also be bound at the same time.