how to export overrideable method

39 views
Skip to first unread message

Kyaw

unread,
Apr 1, 2013, 12:50:03 AM4/1/13
to closure-comp...@googlegroups.com
I have a library that need to export overrideable method (http://dev.yathit.com/api-reference/ydn-db/storage.html#onReady) of an object. 

exportProperty don't not work, because it expose prototype method (class method). 


Did I miss something?

thanpolas

unread,
Apr 1, 2013, 7:15:48 AM4/1/13
to closure-comp...@googlegroups.com
You export methods using an exports file that contains export statements like such:

goog.exportSymbol('ss.sync.send', ssd.sync.send);

Ilia Mirkin

unread,
Apr 1, 2013, 7:24:59 AM4/1/13
to closure-comp...@googlegroups.com
That won't work. There's no (good) way to export writeable properties. You could

(a) Create a function like setOnReady() and export that (or something
similar). This requires a change in your API.
(b) Change the various internal code to refer to foo['onReady']
(c) Add an extern for onReady for that type. I'm not 100% sure it'll
work, but I think it should. This ought to generate equivalent code to
(b).
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "Closure Compiler Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to closure-compiler-d...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Kyaw

unread,
Apr 1, 2013, 9:09:49 PM4/1/13
to closure-comp...@googlegroups.com, imi...@alum.mit.edu
Thanks for extensive solution. 

(a) ugly, but the right way, i believe.
(b) OK, 
(c) unconventional, but this seems like best of both (compiled library user and raw closure user)

Nick Santos

unread,
Apr 2, 2013, 9:26:27 AM4/2/13
to closure-compiler, imi...@alum.mit.edu
You should use @expose.

You misinterpreted the link you pointed to. ALL types of exporting are discouraged for libraries, because the whole point of a library is that it should be compiled out when it's not used. 

But you've already decided you want to export.


To unsubscribe from this group and stop receiving emails from it, send an email to closure-compiler-d...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages