Thursday, February 15, 2018

Re: Understanding JsInterop



On Thursday, February 15, 2018 at 11:01:41 AM UTC+1, Vassilis Virvilis wrote:
Amazing trick!

Obvious if you think about it - but very difficult to think it initially (for us mere mortals).

Well, when you write "element.getBoundingClientRect" in JS (without the parenthesis), this is exactly what you're doing: getting a reference to the function.
In JS, if you call it later, you need to either use .call(element) or .apply(element) to setup the appropriate 'this' element, or you first need to .bind(element) it to the element. I'm not sure how JsInterop works in this case, maybe (probably) my second example wouldn't actually work as it does neither of these (you could use an element2.core.Function to .call()/.apply() or .bind()).

That being said, I didn't came with this pattern by myself either, I believe I saw it somewhere in GWT's emulation library.

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment