Externs: How to define alias methods?

69 views
Skip to first unread message

Daniel Wirtz

unread,
Mar 10, 2013, 6:31:40 PM3/10/13
to closure-comp...@googlegroups.com
Hi,

let's say I have to declarations.

var a = function() {}
var b = function() {}

a.prototype.c = b.prototype.c = function() {}

What's the recommended way for putting that, non-inheritance, down to an extern without just duplicating?

Alan Leung

unread,
Mar 10, 2013, 8:54:20 PM3/10/13
to closure-comp...@googlegroups.com
Would @typedef work for you?




--
 
---
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.
 
 

Daniel Wirtz

unread,
Mar 11, 2013, 12:26:51 PM3/11/13
to closure-comp...@googlegroups.com
Depending on how complex the alias method is, this could become somewhat ugly I think.

For now I am doing the following but I am pretty sure the compiler does not recognize it correctly since b.prototype.c is not an instance but an alias.

/**
 * @constructor
 */
var a = function() {};

a.prototype.c = function() {};

/**
 * @constructor
 */
var b = function() {};

/**
 * @type {a.prototype.c}
 */
b.prototype.c = a.prototype.c;

I also don't know if the following might work:

/**
 * @alias a.prototype.c
 */
b.prototype.c = a.prototype.c;

More ideas?


Am Montag, 11. März 2013 01:54:20 UTC+1 schrieb Alan:
Would @typedef work for you?

On Sun, Mar 10, 2013 at 3:31 PM, Daniel Wirtz <dc...@dcode.io> wrote:
Hi,

let's say I have to declarations.

var a = function() {}
var b = function() {}

a.prototype.c = b.prototype.c = function() {}

What's the recommended way for putting that, non-inheritance, down to an extern without just duplicating?

--
 
---
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-discuss+unsub...@googlegroups.com.

Fredrik Blomqvist

unread,
Mar 11, 2013, 2:40:32 PM3/11/13
to closure-comp...@googlegroups.com
This sounds a bit similar to a question I asked couple of years ago:
https://groups.google.com/d/msg/closure-compiler-discuss/BB2ONeOzUhc/CfZDNomSwd8J
Although my case it was pure functions.

At that time at least the answer was that you simply had to duplicate, or at best create a separate typedef and use it for both declarations.

Regards
/ Fredrik Blomqvist

Chad Killingsworth

unread,
Mar 14, 2013, 3:48:59 PM3/14/13
to closure-comp...@googlegroups.com
This is correct - although there are a few "tricks". Have the alias extend the base type. You must duplicate all static methods. See the jQuery externs for examples ($ is an alias of jQuery).

Chad
Reply all
Reply to author
Forward
0 new messages