Search code examples
javascriptidecode-completion

How to make a IDE recognize JavaScript "class" referenced in other file


I'm starting to develop with JS because I want to learn WebGL. For years I've been using strong typed classes like Java, C++ and C#. But now I'm having heavly issues with JS because it doesnt have classes and variables arent typed...

So i'm trying to use a IDE to help me with some code complete and such. But I'm unable to create a "class" and make it been recognized as it on several IDEs. Tryied NetBeans, Cloud9 and Eclipse: All have the same issue.

Just to referente, this is the class (Matrix4f.js) that i'm trying to use:

if (typeof(exports) === 'undefined') {
    global = typeof(window) !== 'undefined' ? window : this;
}
else {
    global = exports;
}

function Matrix4f(array){
    var mat4f = new Float32Array(array);

    mat4f.translationMatrix = function(x, y, z){
        return new Float32Array([
            1.0, 0.0, 0.0, 0.0,
            0.0, 1.0, 0.0, 0.0,
            0.0, 0.0, 1.0, 0.0,
            x,   y,   z,   1.0
        ]);
};

} 


Matrix4f.create = function(){
    return new Matrix4f([
            1.0, 0.0, 0.0, 0.0,
            0.0, 1.0, 0.0, 0.0,
            0.0, 0.0, 1.0, 0.0,
            0.0, 0.0, 0.0, 1.0
        ]);
};

Matrix4f.translationMatrix = function(x, y, z){
    return new Float32Array([
            1.0, 0.0, 0.0, 0.0,
            0.0, 1.0, 0.0, 0.0,
            0.0, 0.0, 1.0, 0.0,
            x,   y,   z,   1.0
        ]);
};

Matrix4f.scalingMatrix = function(x, y, z){
    return new Float32Array([
            x,   0.0, 0.0, 0.0,
            0.0, y,   0.0, 0.0,
            0.0, 0.0, z,   0.0,
            0.0, 0.0, 0.0, 1.0
        ]);
}; 

global.Matrix4f = Matrix4f;

So event making the import on a Index.html and trying to use the bellow code on other JS file the IDE says that "Matrix4f" is a undeclared variable

var mat4 = Matrix4f.create();
var mat4_2 = new Matrix4f([0.0]);

So I'm doing anything wrong, or this is a limitation of IDEs with JS? Also there is any IDE that doesnt have this problem?

I'm not asking for "the best" I just want to use some code complete...just it! And If I try to use it on browser, it works fine, so there is no syntax error on code (I think).

Anyway, thanks for your help!


Solution

  • If you want to use classes and strongly typed members you can try TypeScript. It is a really nice super-set of javascript and gives you all the good stuff you are used to in Java and C#.

    http://www.typescriptlang.org/

    There are some plugins for some text editors and IDEs, and Visual Studio 2012 supports it very nicely.