|experiences from writing a JSDT plugin [message #759201]
||Sun, 27 November 2011 15:37
| Philippe Marschall
Registered: July 2009
This is a summary of the challenges of writing a jQuery plugin for JSDT .
I'll shortly explain jQuery for those not familiar with it. jQuery
revolves around the jQuery global object called "$" or "jQuery". The
global has several properties some of them are functions for example:
The global object is also a function that an be used to create something
like a collection DOM elements (think composite pattern). This object
offers several functions that generally return that object again. This
allows for cascading function application. Like this:
In this example the class "first" is added to all "a"-elements and then
class "second" is removed from all of them.
This is all that there's to model but I have hit several bumps in trying
to do so.
My approach was to generate jsdoc from the jQuery API XML  instead of
writing a custom type inferencer. With some limitations this worked
fairly well until Indigo SR1 when several things broke.
The first that caused trouble was that prototype of a function is now
only considered when the function is invoked with "new". This is correct
but I my generated jsdoc relied on the old behavior. That one was easy
However the other change was more severe. It appears that now things can
either be functions or object but not both . This meant that suddenly
I could only support half of my use cases either only the ones that
treat "$" as an object or the ones treating it as a function.
So I decided to look at implementing a type inferencer again. But I soon
got the impression that it isn't really well suited for my problem. I
can set the inferred type on function declarations, variable
declarations, assignments and object literals. That's not really the
problem I'm trying to solve. I'm trying to model the "$" global. The
only point where I see a type inferencer would help are arguments of
callback functions because they can't be modeled with jsdoc.
What I really seem need is a custom IJsGlobalScopeInitializer where I
can model the "$" object. However I couldn't find an easy way to do
this. IJsGlobalScopeInitializer seems to revolve around include paths.
My understanding is that this would mean jsdoc again. Am I missing
something here, is there an easy way to programmatically model a global?
Powered by FUDForum
. Page generated in 0.02424 seconds