Defining Custom Scope for Functions

15 views
Skip to first unread message

Joshua Koo

unread,
Jun 16, 2015, 9:40:19 PM6/16/15
to tern...@googlegroups.com
Hi,

I'm exploring if it is easy to define a custom scopes in function so you could get auto-complete suggestions not automatically / easily inferred by tern.

Let's say you have a type defined as in a Child.js

function Child() {
}

Child.prototype.add = function() { }
Child.prototype.remove = function() { }

You are running tern in an editor with simply have

function new_method() {
   this.add()
}

The use case here is eventually new_method as a prototype to child Child.prototype.new_method, and you wish that typing "this." auto-completes ".add", ".remove", but there is no way tern knows what this will eventually be.

Is there an easy way to specify the custom scope for javascript function new_method so that the auto-complete works? For more context, this was brought up in a discussion in https://github.com/mrdoob/three.js/pull/665

Any ideas or suggestions would be great!

Thanks,
Joshua

Marijn Haverbeke

unread,
Jun 24, 2015, 9:02:25 AM6/24/15
to Joshua Koo, tern-dev
The code as is does not provide any hint that new_method will end up
on Child.prototype. If you do have such information, you could write a
plugin that, in a `postInfer` pass, finds such situations in the AST
and propagates the right prototype into the given function's `self`
type.
> --
> You received this message because you are subscribed to the Google Groups
> "tern-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to tern-dev+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages