<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Seems that the semantics of globalEval are also a bit confusing. The code passed to it is evaluated but the value of the last expression isn't returned.</div><div><br></div><div>#asJavascript returns the method/function as a String but I forgot that self is bound to this which will be window in the function.</div><div><br></div><div>The code below works for me in Safari, but yes it's really creepy :-)</div><div><br></div><div><div><span class="Apple-style-span" style="white-space: pre-wrap;"><font class="Apple-style-span" color="#000000" size="3"><span class="Apple-style-span" style="background-color: transparent; font-size: 12px;">- perform: selector with: anObject

        | method evalString |
        @class withAncestors do: [:ea |
                (ea methodAt: selector) ifNotNilDo: [:m | method := m]].
        method ifNil: [self error: 'Method ' , selector , ' not found!'].
        performSelf := self.
        evalString := 'performResult = (' , method asJavascript , ').call(performSelf,' , anObject , ')'.
        evalString globalEval.
        performResult.</span></font></span></div><div><span class="Apple-style-span" style="white-space: pre-wrap;"><br></span></div><div><span class="Apple-style-span" style="white-space: pre-wrap;">Robert</span></div><div><span class="Apple-style-span" style="white-space: pre-wrap;"><br></span></div><div><div><div>On Sep 6, 2009, at 9:48 AM, Avi Bryant wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>On Sat, Sep 5, 2009 at 10:57 AM, Robert<br>Krahn&lt;<a href="mailto:robert.krahn@googlemail.com">robert.krahn@googlemail.com</a>&gt; wrote:<br><br><blockquote type="cite">I expected this to work, however, String&gt;&gt;eval just returns the String. The<br></blockquote><blockquote type="cite">same happens when I try to do&nbsp;'1+1'._eval() in a JS console. Do you know<br></blockquote><blockquote type="cite">where the problem is?<br></blockquote><br>Javascript's eval has confusing semantics - try using globalEval<br>instead. &nbsp;Though, even with that I'm not sure your code would work -<br>what do you expect "method asJavascript" to return? &nbsp;I don't think it<br>will be anything useful.<br><br>Avi<br><br></div></blockquote></div><br></div></div></body></html>