Defining 'this'


we have a very specific use case in our application, a user can create a function that is then processed server side the function has a fixed pattern
function( params, credentials ){}
the interface is provided through codemirror and tern and we have successfully created a plugin for the node modules we allow and definitions for params and credentials.
the this of the function is also fixed and I have created a definition for it but I only get completions when the server is guessing and these are mixed with all the other guesses.

question is is there a way to define this on the top level scope?

Thanks Dave


The way JavaScript (and thus Tern) works is that every function invocation gets its own this, so defining it globally won’t help you. It would be possible to write a plugin that connects your object to the this of all top-level functions defined in the input, maybe that would help.


Thanks Marijn

can you provide an example? looking at the node plugin global has a !type of <top> would i define this as a member of global or is there a way of providing a scope to ThisExpression in infer.js?



Quick update, I am using codemirror so rather than writing a plugin I have used a fileFilter function to wrap the doc with a call so that I can specify the "this"
fileFilter: function(value, docName, doc){
return “(” + value + ").call(epthis, " + params + “, credentials)”;
where epthis and credentials have JSON defs and params is an object works like a charm