[squeak-dev] A question about block closures.

Igor Stasenko siguctua at gmail.com
Wed Jul 8 12:01:09 UTC 2009


David, have you tried to use/evaluate a Prototype package for own purposes?

http://wiki.squeak.org/squeak/1369

2009/7/8 David Goehrig <dave at nexttolast.com>:
> Dear Squeakers,
> I have a question for some of Squeak gurus on the list.  I've been porting a
> javascript project I did a couple months back to Squeak, and in the process
> of porting it, added an ad hoc object class that handled the prototype based
> inheritance I used in the javascript version.
> One of the issues I encountered was that when I did a copy of my object, the
> block closures supplied for various properties required a bit of a hack so I
> have a method:
> doesNotUnderstand: aMessage
> "Generic catch all that performs all selectors"
> (self can: aMessage selector) ifTrue: [
> (self s: aMessage selector ) outerContext receiver: self.
> ^( self s: aMessage selector )valueWithEnoughArguments: aMessage arguments
> ].
> ^ self s: aMessage selector.
> Now this seems to do exactly what I wanted 99% of the time.  It mimics the
> behavior of using a block closure as a javascript function() {} object, and
> all other objects are returned as intended.  The #s: method returns nil if
> the property is not found in the object's dictionary as well, and #can: is
> just a fancy way to test if the property is a block
> closure.  By using valueWithEnoughArguments: it even gets padded out with nils like JS would.
> I'm not entirely happy with how hackish this seems, patching the outerContext and then re-rolling the arguments array to one of the proper size just to copy into a MethodContext.
> My question is "Is there a better way?"
> Dave
> --
> -=-=-=-=-=-=-=-=-=-=- http://blog.dloh.org/
>
>
>
>



-- 
Best regards,
Igor Stasenko AKA sig.



More information about the Squeak-dev mailing list