Reputation: 13881
I am using NetBeans, specifically the HTML5 & PHP bundle. Currently I'm working on a game which makes use of the HTML5 canvas element. I have a global variable called context
:
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
Obviously, the IDE has no idea what type context
is, since it cannot find out the type of canvas
in the first place and it can't possibly know what getContext()
is going to return when called on that canvas
. I would like NetBeans to provide code completion feature for context
assuming it represents a specific type (namely, CanvasRenderingContext2D
). After doing some research I found this: https://blogs.oracle.com/netbeansphp/entry/defining_variable_type_in_a. The site states that such feature can be used in PHP by providing a PHPDoc comment which looks like the following: /* @var $variable type */
. I am aware it concerns PHP, but I decided to give it a try in JavaScript as well:
/* @var context CanvasRenderingContext2D */
Unfortunately, the above did not work. I thought that maybe NetBeans for some reason doesn't know that type and tried something simpler:
/* @var test HTMLImageElement */
Again, there were no proposals for test
except for the ones that are native to all JavaScript objects.
So, is this even possible? I would appreciate it if someone provided a solution. Thanks in advance!
Upvotes: 3
Views: 1586
Reputation: 5876
JavaScript uses JSDoc, not PHPDoc, so you need to use
/** @type HTMLImageElement */
var myImage;
Upvotes: 5